Capitalize every first letter of a word and others to lower case

Monday, February 18, 2013 0 Comments

How can you capitalize(Only first character) each word in a line using perl and change remaining to lower case?

let say there is a file:
> cat temp
hI thIs is woRld
How can we make it
Hi This Is World
Its very simple to do it in perl:
perl -pe 's/(\w+)/\u\L$1/g' your_file
If you want to do it inplace just add a -i flag:
perl -pi -e 's/(\w+)/\u\L$1/g' your_file

0 comments: