1832823 Members
3723 Online
110045 Solutions
New Discussion

Take ^M's out of files

 
SOLVED
Go to solution
Coolmar
Esteemed Contributor

Take ^M's out of files

Hi,

I downloaded some source code that I have to compile. It is for unix, but was created with a .zip extension. Therefore, when I unzip it to unix - every file is full of ^Ms. Does anyone know of a quick way to remove them from all the files in the directory? Or is there a way that with winzip I can extract the files without all the ^M's?
7 REPLIES 7
Rodney Hills
Honored Contributor
Solution

Re: Take ^M's out of files

The standard command is the dos2ux, but to do a lot of them perl works best...

perl -n -i -e 'chomp; print $_,"\n"' *.txt

Will replace them for all .txt files.

HTH

-- Rod Hills
There be dragons...
TwoProc
Honored Contributor

Re: Take ^M's out of files

cat filename | sed -e "s/[ctrl-v ctrl-m]//" > newfilename

by [ctrl-v ctrl-m] I mean you should hit ctrl-v then ctrl-m between the first and second "/" (slash).
We are the people our parents warned us about --Jimmy Buffett
TwoProc
Honored Contributor

Re: Take ^M's out of files

Oh, I forgot - another way (if you're on HPUX) is just run "dos2ux oldfilename > newfilename".
We are the people our parents warned us about --Jimmy Buffett
John Dvorchak
Honored Contributor

Re: Take ^M's out of files

Or how about using the vi editor since you probably have it open in vi anyway. Use the global search and replace:

:%s/^M//g

now to get that you have to type CTL-V and CTL-M but it will look like the example. When you hit CTL-V it will put the ^ symbol then the CTL-M will put the Cap M. To read the command, inside of vi:

%s is search / search-string / replace-string / g globally..

It will replace all ^M with null.
If it has wheels or a skirt, you can't afford it.
Coolmar
Esteemed Contributor

Re: Take ^M's out of files

Thanks for all the suggestions....I have used dos2ux...however, there are about 120 files...I was just hoping there would be a faster way rather than one by one.
A. Clay Stephenson
Acclaimed Contributor

Re: Take ^M's out of files

That's what scripts are for. Who in their right mind would invoke dos2ux 120 times interactively?
If it ain't broke, I can fix that.
Coolmar
Esteemed Contributor

Re: Take ^M's out of files

Extracted the files to my desktop and then ftp'd them to the unix system using ASCII transfer.

Thanks everyone