Saturday, 7 February 2015

Cool tricks in vi editor, convert to upper case, convert to lower case, removing ^M characters etc

Hi there,

In this post, I would post commands/procedures which we use less frequently in our (DBA) job but they are very handy. 

I will be updating this post on regular basis and hopefully with inputs from readers.

To convert all alphabets to upper case in a file, use below string.
Hit 'Esc' and then type:%s/.*/\U&/

To convert all alphabets to lower case in a file, use below string.
Hit 'Esc' and then type:%s/.*/\L&/ 


To delete all the lines matching a pattern in a file, inside vi editor

Command$ Hit 'Esc' and then type :g/<pattern>/d

to delete control M (^M) characters in a file inside vi editor
Command$ :%s/(Ctrl V + Ctrl M)//g

to find and replace word by word
Command$ :%s/existingpattern/ newpattern /gc