regex - Convert first letters of the first 2 words to Upper using sed -


i know can awk, want know how sed. know how convert first letter of each line upper:

sed  's/^\(.\)/\u\1/' input > output 

but want convert first letters of first 2 words upper.

input file:

this file

output file:

this file

i think must doable sed, can't figure out.

you can maybe use -e 2 blocks:

$ echo "this file" | sed -e 's/^\(.\)/\u\1/' -e 's/ \(.\)/ \u\1/' file                    ^^^^^^^^^^^^^^      ^^^^^^^^^^^^^^^                                    first word          second word 

note can make lines more clear -r parameter allows catching simple (xxx) instead of \(xxx\):

$ echo "this file" | sed -re 's/^(.)/\u\1/' -e 's/ (.)/ \u\1/'  file 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -