Trix & Graphix

Uper to lowecase and vice versa

I'm going to tell three ways of doing the same task: changing the capitalization. This is a pretty comon task, and there are many ways of doing it.

The first way is to use my favourite text editor: Vim. The idea is to open the file to be modified. Then, select the whole content of the file and push u to change it to lowercase. Analogously push U to change it to upercase. To select the whole file, you just have to type ggVG. The explanation is as follows: the first gg is to go to the begining of the file, V is for changing to select lines mode, and G to go to the end of the file.


This last way is useful (and fast) if you have to change the content of just one file. It is nevertheless less useful if you have to change many files. In these cases, is better to use awk or sed.

To use awk (my favourite option) you only have to use the function tolower, like in this example:

echo TEXT TO BE CHANGED TO LOWECASE | awk '{print tolower($0)}'

and similary the function toupper changes the string to upercase.

This task may also be achieved with sed. To do it, the command line should be now

echo text to capitals | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'

Well, this is all for today. It looks like the sed way is less elegant. The fact is that I'm pretty sure there must be a better way, althought I don't know it yet ;-).