Wednesday, December 15, 2010

remove Ctrl-M characters in unix

a file edited using windows format might have ^M at the end of each line.
This would be annoying when it comes to the unix world.
Two easy ways to remove this -
1. dos2unix command

2. Vim search & replace

:%s/^V^M//g [ type Ctrl-V Ctrl-M]

this will translate to

:%s/^M//g [ remember Ctrl-V is escape sequence in Unix]