Translating part of a line
I want to change the first character of each line to upper case.
Sample input: Quote:
Quote:
Code:
sed 's/\([a-z]\)\([a-zA-Z0-9]*\)/\u\1\2/g' $InFile Code:
sed 's/\([a-z]\)\(.*\)/\u\1\2/' $InFile Daniel B. Martin |
It is an escape sequence meaning upper case.
For less confusing solution: Code:
awk 'BEGIN{ FS=""; OFS="" }{ $1=toupper($1); print $0 }' input |
The sed code you posted will capitalize the first letter of every word, if you just need the first letter of a line, it can be simpler:
Code:
sed 's/^./\u&/' $InFile |
Hi.
Quote:
Code:
$ echo abba dav | sed 's/\b./\u&/g' Similarly, you can capitalize last character of each word Code:
$ echo abba dav | sed 's/.\b/[\u&]/g' Quote:
|
Thank you, H_TexMex_H, ntubski, and firstfire for useful contributions to this thread. Double thanks to ntubski for providing a pointer to the place where I can learn more on this subject.
I am in awe of the amazing range of operations of which sed is capable. We can mark this thread SOLVED! Daniel B. Martin |
bash-only solutions (version 4+), using parameter substitution:
Code:
while read line; do Code:
mapfile -t lines <origfile.txt |
All times are GMT -5. The time now is 09:35 PM. |