Remove ^M from file in unix file
This note is dedicated to my chubby hubby that keep asking me how to remove ^M in a file.
UNIX treats the end of line differently than other operating systems. Normally CTRL-M character is visibly displayed at the end of each line as ^M if the file is not transfered in binary mode (this is why I always prefer SFTP instead of FTP).
- In vi, to remove the ^M do as following :
- with Solaris you can just do (heard HPUX has the command “dos2ux” instead of dos2unix):
- You can also use the octal representatiion of ^M:
:%s/^V^M//g
^V is a CONTROL-V character
^M is a CONTROL-M.
So it will look like this:
:%s/^M//g
%s is a basic search and replace command in vi.
The g is use for search and replace globally (all occurrences).
dos2unix <dos file> <unix file>
tr -d ‘\015\032′ < file

May 11th, 2008 at 12:14 am
tq honey…very helpfull
[Reply]
May 11th, 2008 at 3:45 pm
Terima kasih atas ingatan.
[Reply]