July 25, 2006
Removing CRLF Using Vi
Posted by: admin : Category: Editors
Sometimes DOS files end up on unix systems without being converted. Files will then have those nasty ^M character at the line ending, which prevents some applications to work properly.
The reason for is is DOS to use CRLF (carriage return + line feed) for line endings while unix uses LF (line feed) only.
If only few files need to be changed, vi/vim is the tool of choice.
After opening up the file, enter command mode to run this macro:
:%s/^M$//g
To get the ^M do not actually enter it as is. Insert it by typing the CTRL-V CTRL-M sequence instead.
March 14th, 2009 at 1:49 pm
It’s the first time I commented here and I should say that you provide genuine, and quality information for bloggers! Great job.
p.s. You have an awesome template . Where have you got it from?
February 1st, 2012 at 1:21 am
You could also do the following from the command line:
strings oldfile>>newfile
Not as eloquent, but does the job.
February 5th, 2012 at 6:47 pm
True, and also using any of dos2unix, tr or sed.
The point is, that I was editing the file in vi, this is why I was posting it 😉