Thursday, 28 August 2008

Removing line feed characters from dos files for use in UNIX

Here are a couple of commands to remove line feeds from files created in windows for use in UNIX.
I had a list of usernames in a csv which I wanted to run an ldap search on however the line feed characters were causing this to mess up the command

To get around this you can either run

dos2unix current.csv newfile.csv

or you can open the text file in vi. The text file looked like this

johnhe02^M
paulke04^M
marymc04^M
elainp02^M
jimfor01^M
markad01^M
johnmc12^M


then basically open up your command prompt by pressing the colon key ":", and enter the following

%s/^M//g

Note to get the ^M character you hold down ctrl and press V and then M (V and M must be pressed while holding down ctrl)

Another way to acheive the same results as dos2unix is by using the flip command. Thanks to Jadu Kumar Saikia for pointing this out :o)

1 comment:

Jadu Kumar Saikia said...

Another alternative to unix2dos and dos2unix(debian tofrodos package) is linux flip command

http://unstableme.blogspot.com/2008/04/linux-flip-command-alternative-of.html

// Jadu