How to convert the first letter of the nth column of a csv file to uppercase?How to output MySQL query results in CSV format?How do I tell if a regular file does not exist in Bash?Dealing with commas in a CSV fileHow can I redirect and append both stdout and stderr to a file with Bash?Save PL/pgSQL output from PostgreSQL to a CSV fileHow to convert a string to lower case in Bash?How to import CSV file data into a PostgreSQL table?Bash tool to get nth line from a fileChange first line of CSV file to all uppercasehow do I map one csv to another with ruby
IList<T> implementation
Can inductive kick be discharged without freewheeling diode, in this example?
Unexpected behavior after assignment of function object to function wrapper
Find the logic in first 2 statements to give the answer for the third statement
Create a list of snaking numbers under 50,000
Is this homebrew "Faerie Fire Grenade" unbalanced?
What checks exist against overuse of presidential pardons in the USA?
Printing a list as "a, b, c." using Python
Don't look at what I did there
What caused the end of cybernetic implants?
What are ways to record who took the pictures if a camera is used by multiple people?
Can UV radiation be safe for the skin?
Why does the U.S. military maintain their own weather satellites?
What am I looking at here at Google Sky?
Is the word 'mistake' a concrete or abstract noun?
Why is there no Disney logo in MCU movies?
Did the Apollo Guidance Computer really use 60% of the world's ICs in 1963?
Can I lend a small amount of my own money to a bank at the federal funds rate?
LWC: Is it safe to rely on window.location.href to get the page url?
Can authors email you PDFs of their textbook for free?
Am I required to correct my opponent's assumptions about my morph creatures?
Why do presidential pardons exist in a country having a clear separation of powers?
Cheap oscilloscope showing 16 MHz square wave
Properly unlinking hard links
How to convert the first letter of the nth column of a csv file to uppercase?
How to output MySQL query results in CSV format?How do I tell if a regular file does not exist in Bash?Dealing with commas in a CSV fileHow can I redirect and append both stdout and stderr to a file with Bash?Save PL/pgSQL output from PostgreSQL to a CSV fileHow to convert a string to lower case in Bash?How to import CSV file data into a PostgreSQL table?Bash tool to get nth line from a fileChange first line of CSV file to all uppercasehow do I map one csv to another with ruby
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Column 12 in a csv file is all uppercase. Sometimes the column has 3 words but for the most part, it has 1 word.
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","TWELVE","thirteen"
I am wanting to convert column four to only have the first letter uppercase
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","Twelve","thirteen"
I can make the entire column to lower case:
awk -F"," 'BEGINOFS="," $12 = tolower($12); print' "$tmp_input3" > "$tmp_input4"
and that command gives me:
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen"
How do I make the first letter of the 12th column to be upper case?
bash csv sed
add a comment |
Column 12 in a csv file is all uppercase. Sometimes the column has 3 words but for the most part, it has 1 word.
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","TWELVE","thirteen"
I am wanting to convert column four to only have the first letter uppercase
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","Twelve","thirteen"
I can make the entire column to lower case:
awk -F"," 'BEGINOFS="," $12 = tolower($12); print' "$tmp_input3" > "$tmp_input4"
and that command gives me:
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen"
How do I make the first letter of the 12th column to be upper case?
bash csv sed
1
toupper( substr( $12, 1, 1 ) ) substr( $12, 2 )
– Wiktor Stribiżew
Mar 27 at 23:13
edit your question to include a minimal reproducible example with concise, testable sample input and expected output. Include more than just the sunny day cases (e.g. include a case where the first letter isn't the first character such as7foo bar
). See How to Ask if that's not clear.
– Ed Morton
Mar 27 at 23:16
@WiktorStribiżew Can you correct my syntax?awk -F"," 'BEGINOFS="," $12 = toupper( substr( $12, 1, 1 ) ) substr( $12, 2 ); print' "$tmp_input4" > "$tmp_input5"
– Curious Sam
Mar 27 at 23:17
I guess"$tmp_input4"
contains the file path and"$tmp_input5"
is the new file path.
– Wiktor Stribiżew
Mar 27 at 23:18
So - no fields where the first char is non-alphabetic (10 Downing St.
)? No fields that contain commas ("foo, bar"
)? Nothing else a script might have to specifically handle? Really think about your real data and post sample input/output that's representative of that - don't just throw up a bunch of sunny day single lower case words unless that truly is all you have in your input (which from your previous questions it isn't).
– Ed Morton
Mar 27 at 23:48
add a comment |
Column 12 in a csv file is all uppercase. Sometimes the column has 3 words but for the most part, it has 1 word.
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","TWELVE","thirteen"
I am wanting to convert column four to only have the first letter uppercase
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","Twelve","thirteen"
I can make the entire column to lower case:
awk -F"," 'BEGINOFS="," $12 = tolower($12); print' "$tmp_input3" > "$tmp_input4"
and that command gives me:
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen"
How do I make the first letter of the 12th column to be upper case?
bash csv sed
Column 12 in a csv file is all uppercase. Sometimes the column has 3 words but for the most part, it has 1 word.
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","TWELVE","thirteen"
I am wanting to convert column four to only have the first letter uppercase
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","Twelve","thirteen"
I can make the entire column to lower case:
awk -F"," 'BEGINOFS="," $12 = tolower($12); print' "$tmp_input3" > "$tmp_input4"
and that command gives me:
"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen"
How do I make the first letter of the 12th column to be upper case?
bash csv sed
bash csv sed
edited Mar 27 at 23:27
Curious Sam
asked Mar 27 at 23:10
Curious SamCurious Sam
14910 bronze badges
14910 bronze badges
1
toupper( substr( $12, 1, 1 ) ) substr( $12, 2 )
– Wiktor Stribiżew
Mar 27 at 23:13
edit your question to include a minimal reproducible example with concise, testable sample input and expected output. Include more than just the sunny day cases (e.g. include a case where the first letter isn't the first character such as7foo bar
). See How to Ask if that's not clear.
– Ed Morton
Mar 27 at 23:16
@WiktorStribiżew Can you correct my syntax?awk -F"," 'BEGINOFS="," $12 = toupper( substr( $12, 1, 1 ) ) substr( $12, 2 ); print' "$tmp_input4" > "$tmp_input5"
– Curious Sam
Mar 27 at 23:17
I guess"$tmp_input4"
contains the file path and"$tmp_input5"
is the new file path.
– Wiktor Stribiżew
Mar 27 at 23:18
So - no fields where the first char is non-alphabetic (10 Downing St.
)? No fields that contain commas ("foo, bar"
)? Nothing else a script might have to specifically handle? Really think about your real data and post sample input/output that's representative of that - don't just throw up a bunch of sunny day single lower case words unless that truly is all you have in your input (which from your previous questions it isn't).
– Ed Morton
Mar 27 at 23:48
add a comment |
1
toupper( substr( $12, 1, 1 ) ) substr( $12, 2 )
– Wiktor Stribiżew
Mar 27 at 23:13
edit your question to include a minimal reproducible example with concise, testable sample input and expected output. Include more than just the sunny day cases (e.g. include a case where the first letter isn't the first character such as7foo bar
). See How to Ask if that's not clear.
– Ed Morton
Mar 27 at 23:16
@WiktorStribiżew Can you correct my syntax?awk -F"," 'BEGINOFS="," $12 = toupper( substr( $12, 1, 1 ) ) substr( $12, 2 ); print' "$tmp_input4" > "$tmp_input5"
– Curious Sam
Mar 27 at 23:17
I guess"$tmp_input4"
contains the file path and"$tmp_input5"
is the new file path.
– Wiktor Stribiżew
Mar 27 at 23:18
So - no fields where the first char is non-alphabetic (10 Downing St.
)? No fields that contain commas ("foo, bar"
)? Nothing else a script might have to specifically handle? Really think about your real data and post sample input/output that's representative of that - don't just throw up a bunch of sunny day single lower case words unless that truly is all you have in your input (which from your previous questions it isn't).
– Ed Morton
Mar 27 at 23:48
1
1
toupper( substr( $12, 1, 1 ) ) substr( $12, 2 )
– Wiktor Stribiżew
Mar 27 at 23:13
toupper( substr( $12, 1, 1 ) ) substr( $12, 2 )
– Wiktor Stribiżew
Mar 27 at 23:13
edit your question to include a minimal reproducible example with concise, testable sample input and expected output. Include more than just the sunny day cases (e.g. include a case where the first letter isn't the first character such as
7foo bar
). See How to Ask if that's not clear.– Ed Morton
Mar 27 at 23:16
edit your question to include a minimal reproducible example with concise, testable sample input and expected output. Include more than just the sunny day cases (e.g. include a case where the first letter isn't the first character such as
7foo bar
). See How to Ask if that's not clear.– Ed Morton
Mar 27 at 23:16
@WiktorStribiżew Can you correct my syntax?
awk -F"," 'BEGINOFS="," $12 = toupper( substr( $12, 1, 1 ) ) substr( $12, 2 ); print' "$tmp_input4" > "$tmp_input5"
– Curious Sam
Mar 27 at 23:17
@WiktorStribiżew Can you correct my syntax?
awk -F"," 'BEGINOFS="," $12 = toupper( substr( $12, 1, 1 ) ) substr( $12, 2 ); print' "$tmp_input4" > "$tmp_input5"
– Curious Sam
Mar 27 at 23:17
I guess
"$tmp_input4"
contains the file path and "$tmp_input5"
is the new file path.– Wiktor Stribiżew
Mar 27 at 23:18
I guess
"$tmp_input4"
contains the file path and "$tmp_input5"
is the new file path.– Wiktor Stribiżew
Mar 27 at 23:18
So - no fields where the first char is non-alphabetic (
10 Downing St.
)? No fields that contain commas ("foo, bar"
)? Nothing else a script might have to specifically handle? Really think about your real data and post sample input/output that's representative of that - don't just throw up a bunch of sunny day single lower case words unless that truly is all you have in your input (which from your previous questions it isn't).– Ed Morton
Mar 27 at 23:48
So - no fields where the first char is non-alphabetic (
10 Downing St.
)? No fields that contain commas ("foo, bar"
)? Nothing else a script might have to specifically handle? Really think about your real data and post sample input/output that's representative of that - don't just throw up a bunch of sunny day single lower case words unless that truly is all you have in your input (which from your previous questions it isn't).– Ed Morton
Mar 27 at 23:48
add a comment |
2 Answers
2
active
oldest
votes
This might work for you (GNU sed):
sed 's/[^",]+/Lu&/12' file
This converts the twelfth string which is one or more characters long and is neither a comma or a double quotes, to lowercase except for the first character which it uppercases.
add a comment |
You may use toupper(substr($12,1,1)) substr($12, 2)
:
awk -F"," 'BEGINOFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' "$tmp_input3" > "$tmp_input4"
That is, you turn the first char to upper case with toupper(substr($12,1,1))
and then append the rest of the chars beginning from Index 2.
See the online awk
demo:
s="1,2,3,4,5,6,7,8,9,10,11,abc def ghi,end"
awk 'BEGINFS=OFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' <<< "$s"
# => 1,2,3,4,5,6,7,8,9,10,11,Abc def ghi,end
This fails if there is only one word in the 12th column
– Curious Sam
Mar 27 at 23:42
1
@CuriousSam no it doesn't, Wiktor just answered before you posted the sample input/output so he didn't know that your fields are quoted.
– Ed Morton
Mar 27 at 23:47
@CuriousSam Even if there is a single letter word, it does not fail.
– Wiktor Stribiżew
Mar 28 at 0:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387867%2fhow-to-convert-the-first-letter-of-the-nth-column-of-a-csv-file-to-uppercase%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This might work for you (GNU sed):
sed 's/[^",]+/Lu&/12' file
This converts the twelfth string which is one or more characters long and is neither a comma or a double quotes, to lowercase except for the first character which it uppercases.
add a comment |
This might work for you (GNU sed):
sed 's/[^",]+/Lu&/12' file
This converts the twelfth string which is one or more characters long and is neither a comma or a double quotes, to lowercase except for the first character which it uppercases.
add a comment |
This might work for you (GNU sed):
sed 's/[^",]+/Lu&/12' file
This converts the twelfth string which is one or more characters long and is neither a comma or a double quotes, to lowercase except for the first character which it uppercases.
This might work for you (GNU sed):
sed 's/[^",]+/Lu&/12' file
This converts the twelfth string which is one or more characters long and is neither a comma or a double quotes, to lowercase except for the first character which it uppercases.
answered Mar 29 at 0:00
potongpotong
38.4k4 gold badges33 silver badges64 bronze badges
38.4k4 gold badges33 silver badges64 bronze badges
add a comment |
add a comment |
You may use toupper(substr($12,1,1)) substr($12, 2)
:
awk -F"," 'BEGINOFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' "$tmp_input3" > "$tmp_input4"
That is, you turn the first char to upper case with toupper(substr($12,1,1))
and then append the rest of the chars beginning from Index 2.
See the online awk
demo:
s="1,2,3,4,5,6,7,8,9,10,11,abc def ghi,end"
awk 'BEGINFS=OFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' <<< "$s"
# => 1,2,3,4,5,6,7,8,9,10,11,Abc def ghi,end
This fails if there is only one word in the 12th column
– Curious Sam
Mar 27 at 23:42
1
@CuriousSam no it doesn't, Wiktor just answered before you posted the sample input/output so he didn't know that your fields are quoted.
– Ed Morton
Mar 27 at 23:47
@CuriousSam Even if there is a single letter word, it does not fail.
– Wiktor Stribiżew
Mar 28 at 0:11
add a comment |
You may use toupper(substr($12,1,1)) substr($12, 2)
:
awk -F"," 'BEGINOFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' "$tmp_input3" > "$tmp_input4"
That is, you turn the first char to upper case with toupper(substr($12,1,1))
and then append the rest of the chars beginning from Index 2.
See the online awk
demo:
s="1,2,3,4,5,6,7,8,9,10,11,abc def ghi,end"
awk 'BEGINFS=OFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' <<< "$s"
# => 1,2,3,4,5,6,7,8,9,10,11,Abc def ghi,end
This fails if there is only one word in the 12th column
– Curious Sam
Mar 27 at 23:42
1
@CuriousSam no it doesn't, Wiktor just answered before you posted the sample input/output so he didn't know that your fields are quoted.
– Ed Morton
Mar 27 at 23:47
@CuriousSam Even if there is a single letter word, it does not fail.
– Wiktor Stribiżew
Mar 28 at 0:11
add a comment |
You may use toupper(substr($12,1,1)) substr($12, 2)
:
awk -F"," 'BEGINOFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' "$tmp_input3" > "$tmp_input4"
That is, you turn the first char to upper case with toupper(substr($12,1,1))
and then append the rest of the chars beginning from Index 2.
See the online awk
demo:
s="1,2,3,4,5,6,7,8,9,10,11,abc def ghi,end"
awk 'BEGINFS=OFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' <<< "$s"
# => 1,2,3,4,5,6,7,8,9,10,11,Abc def ghi,end
You may use toupper(substr($12,1,1)) substr($12, 2)
:
awk -F"," 'BEGINOFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' "$tmp_input3" > "$tmp_input4"
That is, you turn the first char to upper case with toupper(substr($12,1,1))
and then append the rest of the chars beginning from Index 2.
See the online awk
demo:
s="1,2,3,4,5,6,7,8,9,10,11,abc def ghi,end"
awk 'BEGINFS=OFS="," $12 = toupper(substr($12,1,1)) substr($12, 2)1' <<< "$s"
# => 1,2,3,4,5,6,7,8,9,10,11,Abc def ghi,end
answered Mar 27 at 23:17
Wiktor StribiżewWiktor Stribiżew
355k16 gold badges170 silver badges253 bronze badges
355k16 gold badges170 silver badges253 bronze badges
This fails if there is only one word in the 12th column
– Curious Sam
Mar 27 at 23:42
1
@CuriousSam no it doesn't, Wiktor just answered before you posted the sample input/output so he didn't know that your fields are quoted.
– Ed Morton
Mar 27 at 23:47
@CuriousSam Even if there is a single letter word, it does not fail.
– Wiktor Stribiżew
Mar 28 at 0:11
add a comment |
This fails if there is only one word in the 12th column
– Curious Sam
Mar 27 at 23:42
1
@CuriousSam no it doesn't, Wiktor just answered before you posted the sample input/output so he didn't know that your fields are quoted.
– Ed Morton
Mar 27 at 23:47
@CuriousSam Even if there is a single letter word, it does not fail.
– Wiktor Stribiżew
Mar 28 at 0:11
This fails if there is only one word in the 12th column
– Curious Sam
Mar 27 at 23:42
This fails if there is only one word in the 12th column
– Curious Sam
Mar 27 at 23:42
1
1
@CuriousSam no it doesn't, Wiktor just answered before you posted the sample input/output so he didn't know that your fields are quoted.
– Ed Morton
Mar 27 at 23:47
@CuriousSam no it doesn't, Wiktor just answered before you posted the sample input/output so he didn't know that your fields are quoted.
– Ed Morton
Mar 27 at 23:47
@CuriousSam Even if there is a single letter word, it does not fail.
– Wiktor Stribiżew
Mar 28 at 0:11
@CuriousSam Even if there is a single letter word, it does not fail.
– Wiktor Stribiżew
Mar 28 at 0:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387867%2fhow-to-convert-the-first-letter-of-the-nth-column-of-a-csv-file-to-uppercase%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
toupper( substr( $12, 1, 1 ) ) substr( $12, 2 )
– Wiktor Stribiżew
Mar 27 at 23:13
edit your question to include a minimal reproducible example with concise, testable sample input and expected output. Include more than just the sunny day cases (e.g. include a case where the first letter isn't the first character such as
7foo bar
). See How to Ask if that's not clear.– Ed Morton
Mar 27 at 23:16
@WiktorStribiżew Can you correct my syntax?
awk -F"," 'BEGINOFS="," $12 = toupper( substr( $12, 1, 1 ) ) substr( $12, 2 ); print' "$tmp_input4" > "$tmp_input5"
– Curious Sam
Mar 27 at 23:17
I guess
"$tmp_input4"
contains the file path and"$tmp_input5"
is the new file path.– Wiktor Stribiżew
Mar 27 at 23:18
So - no fields where the first char is non-alphabetic (
10 Downing St.
)? No fields that contain commas ("foo, bar"
)? Nothing else a script might have to specifically handle? Really think about your real data and post sample input/output that's representative of that - don't just throw up a bunch of sunny day single lower case words unless that truly is all you have in your input (which from your previous questions it isn't).– Ed Morton
Mar 27 at 23:48