Thursday, August 7, 2014

Remove ^M from Windows text files in Unix

If you manipulate with files in ascii format from Windows in Unix environment you will get ^M end of the line character.
To remove it open VI

Type
:%s/(ctrl-v)(ctrl-m)//g
Enter
:x (save and exit)

This will remove ^M, however if you need to substitute ^M with a new line use:
:%s/(ctrl-v)(ctrl-m)/\r/g
Enter
:x (save and exit)