Operating System - HP-UX
1820477 Members
2915 Online
109624 Solutions
New Discussion юеВ

How to remove these carriage returns

 
Hunki
Super Advisor

How to remove these carriage returns

I have this file sent to me by someone running windows ( my guess ) , how to can I remove these ^M

DEBUG_ON=true^M
# DEBUG_ON=false^M
^M
# Region we are running in^M
6 REPLIES 6
Victor BERRIDGE
Honored Contributor

Re: How to remove these carriage returns

use dos2ux!

dos2ux yourfile>newfile


All the best
Victor
Sandman!
Honored Contributor

Re: How to remove these carriage returns

Run dos2ux on them. The pair of newline+carriage return characters are the windows line terminator as opposed to Unix which has only newline. And dos2ux utility will do just that i.e. strip away the carriage return (^M) from the end of each line.

cheers!
Kent Ostby
Honored Contributor

Re: How to remove these carriage returns

vi the file

do the following key sequence
:s/cntl-Vcntl-M//

where cntl-V and cntl-M are single key strokes
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Jeff_Traigle
Honored Contributor

Re: How to remove these carriage returns

If you happen to already be in vi when you notice this, you can fix it immediately without exiting and running the dos2ux tool:

:1,$s/^V^M//
:w
--
Jeff Traigle
A. Clay Stephenson
Acclaimed Contributor

Re: How to remove these carriage returns

Or something as simple as:
tr -d "\015" < infile > outfile
If it ain't broke, I can fix that.
Hunki
Super Advisor

Re: How to remove these carriage returns

Thanks for the dos2ux.