Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BASH - Make the first Letter Uppercase

I try to capitalize the first letter in a CSV which is sorted like this:

a23;asd23;sdg3

What i want is a output like this

a23;Asd23;Sdg3

So the first String should be as is, but the second and third should have a capitalized first letter. I tried with AWK and SED but i didn't find the right solution. Can someone help?

like image 280
fwaechter Avatar asked Oct 06 '10 12:10

fwaechter


People also ask

How do you capitalize the first letter in Linux?

Use ^ to convert the first letter to uppercase and ^^ to convert all characters to uppercase. Use , to convert the first letter to lowercase and ,, to convert all characters to lowercase. Use ~ to toggles the case for the first character and ~~ to toggle cases for all characters.

How do you capitalize the first letter in Unix?

@CMCDragonkai: To lowercase the first letter, use "${foo,}" . To lowercase all the letters, use "${foo,,}" . To uppercase all the letters, use "${foo^^}" .

How do you get the first letter of a string Capital?

To capitalize the first character of a string, We can use the charAt() to separate the first character and then use the toUpperCase() function to capitalize it.

How do you capitalize a shell script?

The ^ operator converts to uppercase, while , converts to lowercase. If you double-up the operators, ie, ^^ or ,, , it applies to the whole string; otherwise, it applies only to the first letter (that isn't absolutely correct - see "Advanced Usage" below - but for most uses, it's an adequate description).


1 Answers

Just capitilise all letters that follow a semicolon:

sed -e 's/;./\U&\E/g'
like image 68
Bart Sas Avatar answered Sep 20 '22 19:09

Bart Sas