Caplitalize(change to uppercase )first letter of each word in a line

Thursday, January 03, 2013 0 Comments

How can you capitalize each word in a line using perl?

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/\b(\w)/\U$1/g;' your_file


if you want to do it inplace just add  a -i flag:

perl -pi -e '$_=~s/\b(\w)/\U$1/g;' your_file

0 comments: