1847211 Members
2509 Online
110263 Solutions
New Discussion

Re: Remove ^M from shell

 
SOLVED
Go to solution
Jeeshan
Honored Contributor

Remove ^M from shell

Dear all

i'v upload the nickel in my servers from windows machine.
but it shows ^M in every line. how can i remove this with command?
a warrior never quits
10 REPLIES 10
Oviwan
Honored Contributor

Re: Remove ^M from shell

hey

check the command: dos2ux
or search in this forum, you will find a lot of topics.

Regards
Steven E. Protter
Exalted Contributor
Solution

Re: Remove ^M from shell

Shalom,

1) You have made a mistake with ascii/binary in your ftp transfer. The windows ftp client defaults to ascii which probably caused this.
2) dos2unix normally fixes this problem, but you may also have to do the download/uplaod over again properly.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Roberto Arias
Valued Contributor

Re: Remove ^M from shell

hi all

try first transfer file in binary mode.

you can try 'dos2ux > >file_good' too

regards
The man is your friend
Laurent Menase
Honored Contributor

Re: Remove ^M from shell

the old way:
tr -d "\015" file.out
kggj
Advisor

Re: Remove ^M from shell

Here is the tested and proved method to take away the ^M from any file.


# To take off the control chars from a file
# vi fn

Then Esc column and do the foloowing >

:%s/^M/ ( ie, control v control m) and enter .

This will take away the control Chracters.

If its a small file, you can even do # cat filename > newname


Rgds/ Kggj
MikeL_4
Super Advisor

Re: Remove ^M from shell

using vi:

To remove the characters use the command sequence
:1,$s/^V^M//
followed by a return.
Note: Please be aware that the ^V will not echo on your screen,
but ^M will.
Geoff Wild
Honored Contributor

Re: Remove ^M from shell

Here's a link on handling characters with sed:

http://www-h.eng.cam.ac.uk/help/tpl/unix/sed.html


# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # gsed 3.02.80, but top script is easier


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
James R. Ferguson
Acclaimed Contributor

Re: Remove ^M from shell

HI:

# perl -pe 's%\r\n%\n%; s%\032%% if eof' file

...mimics the HP-UX 'dos2ux' command including handling the 'sub' character (^Z) that marks the end of a DOS file.

To update your file(s) inplace and keep a backup copy as '.old', do:

# perl -pi.old -e 's%\r\n%\n%; s%\032%% if eof' file

Regards!

...JRF...


Jeeshan
Honored Contributor

Re: Remove ^M from shell

Thanks steven for correction.
I have uploaded in binary mode, it'll be in ascii mode.

Thanks everyone for your great support.
a warrior never quits
Steve Post
Trusted Contributor

Re: Remove ^M from shell

One thing about using sed to remove the control-M. It is possible for files to sometimes have text but no lines. I had an EDI file like this. If this is the case, the sed command will not remove the control-M because it never had a complete line to work on.