1823924 Members
3130 Online
109667 Solutions
New Discussion юеВ

Strange code in file

 
SOLVED
Go to solution
hangyu
Regular Advisor

Strange code in file

I use vi to edit a file , but suddenly found that there is a ^M at the end of each line , it heppens sometimes , can advise how to fix it , and delete this code in the file by one time ? thx .
7 REPLIES 7
Sandman!
Honored Contributor
Solution

Re: Strange code in file

Remove the ^M characters using dos2ux utility. See dos2ux(1) for details; for ex.

# dos2ux infile > outfile
Peter Godron
Honored Contributor

Re: Strange code in file

Hi,
the control M is a sign of different interpretation of line termination, between Win and UNIX.
See:
http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=1014542
hangyu
Regular Advisor

Re: Strange code in file

thx ,

except use dos2ux , how to remove it in the file ? thx
V. Nyga
Honored Contributor

Re: Strange code in file

Hi,

you can simply erase it!
It is seen as one letter.

But better is dos2ux.

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
James R. Ferguson
Acclaimed Contributor

Re: Strange code in file

Hi:

In lieu of 'dos2ux' you can use:

# perl -pi.old -e 's/\r\n/\n/;s/\032//' file

This eliminates not only the carriage-return (^M) but also an end-of-file "^Z" charcters found in Windows (DOS) files.

A backup copy of your 'file' will be made as 'file.old'. When done, 'file' will have been "repaired".

Regards!

...JRF...
Arturo Galbiati
Esteemed Contributor

Re: Strange code in file

Hi,
in Vi just type:
:%s/^M//g

to obtain ^M type ctrl-V ctrl-M

HTH,
Art
Frank de Vries
Respected Contributor

Re: Strange code in file

you can just remove them.
With sed.
sed 's/^M$//g' < your_file

# in bash/tcsh, press Ctrl-V then Ctrl-M

Also keep this links handy , with one-liners
for sed. Quite nice

http://www.student.northpark.edu/pemente/sed/sed1line.txt
Look before you leap