[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: stripping the ^M

Quoting Cimarron Ryan (cryan mail wesleyan edu):
> Just for kicks, I decided to try and strip the nasty ^M from windows/dos
> text files using sed.
> $ sed -e s/^M//g filename
> doesn't work.  And neither does
> $ sed -e s/\^M//g filename
> How can you match control characters in the regexp?

Okay...just for completeness, here are two other solutions that don't use
the dos2unix binary.  The first one uses perl, and it's my favorite.

$ perl -p -i.bak -e 's/\015//g' filename

If you don't have dos2unix (but you do have perl), just put the following
in your .tcshrc:

alias dos2unix "perl -p -i.bak -e 's/\015//g'"

or if you're using bash put this in your .bashrc:
alias dos2unix="perl -p -i.bak -e 's/\015//g'"

If you don't have Perl, you can always use tr to strip the newlines.  If you
have GNU tr you can use this:

$ tr -d '\r' < filename > new_filename

If you have some older version of tr, this should always work:

$ tr -d '\015' < filename > new_filename

Michael A. Jarvis, Senior Technology Consultant
Insource Technology, Houston, TX  USA http://www.insource.com
Email:  michaelj insource com        Telephone:  281.774.4096
RSA PGP Key:  0x1F1D5425             DSS PGP Key:  0x44D20912

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]