[lug] File conversion question

Jeff Schroeder jeff at neobox.net
Thu Nov 18 17:32:17 MST 2004

Paul asked:

> I have come into the posession of a large number of text files
> that have a ^M where there should be a \n character. What is the
> 'well known' trick for conversion to UNIX-tradition format using
> POSIX commands?

I thought there was a command "dos2unix" or something, but I can't find 
it.  A while back I wrote myself a little bash script that does exactly 

for file in `find -type f`; do sed -i s/^M// $file; done

Note that when I created this script in vi, I used a control-V control-M 
to insert the ^M in the 'sed' command.  YMMV depending on what editor 
you're using.

Basically this just goes through all files (descending the directory 
hierarchy-- careful!) and replaces ^M with nothing.  You can obviously 
change the 'for' loop appropriately.


More information about the LUG mailing list