Replace the first letter of each line by a capital

Hi,

I need to replace, as the title says, the first letter of each line (when it's not a number) by the same letter, but capital.

For instance :

hello
Who
123pass

Would become :

Hello
Who
123pass

Is there a way with sed to do that ? Or other unix command ?

Thank you :slight_smile:

with man sed (linux):

sed -e 's/^./\U&/'

Thank you for this quick answer ! It is working perfectly fine :slight_smile:

perl -pe '$_=ucfirst' ganon551.file

Thank you for this answers :slight_smile:

By the way, do you also have a magic command to remove lines that are longer or smaller than a number ?

For instance remove all the lines in a file that are longer than 20 caracters, remove others that are smaller than 5 caracters, etc.

Thank you :slight_smile:

Remove lines longer than 20, not counting the end of line character

perl -nle 'length() <= 20 and print'

Remove lines shorter than 5, not counting the end of line character

perl -nle 'length() >= 5 and print'

Both in one

perl -nle 'length() >= 5 and length() <= 20 and print'

If the end of line character must be counted, remove the ` l ' flag from -nle

Perl is one way, but since there is usually more than one way to do this:

awk '5 <= length && length <= 20'
sed -ne '/^.\{5,20\}$/p'
1 Like

Thank you again :slight_smile:

I'll read a tutorial about sed, so I won't bother people anymore :smiley: