How to change case of text in a file?

There are few ways to change case of text in a file from lower case to upper case or vice-versa.

1) Using dd, the conv option are ucase for upper case and lcase for lower case.
$ cat test.dat
sdfsf
dsfsaf
$ dd if=test.dat of=large_file conv=ucase
0+1 records in.
0+1 records out.
$ cat large_file
SDFSF
DSFSAF

2) Using tr
$ cat test.dat | tr ‘[a-z]’ ‘[A-Z]’
SDFSF
DSFSAF

OR

$ cat test.dat | tr ‘[:lower:]’ ‘[:upper:]’
SDFSF
DSFSAF

OR

Using vi
:%s/[A-Z]/\L&/g # convert letters to lower case
:%s/[a-z]/\U&/g # convert letters to upper case

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s