stripping_control_Ms

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



===
From: Michael Jarvis <michaelj@burrito.insource.com>
Date: Mon, 12 Apr 1999 09:12:04 -0500
Subject: 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

===

From: Steve Borho <sborho@ststech.com>
Date: Fri, 9 Apr 1999 10:01:57 -0500
Subject: Re: Re: stripping the ^M


On Fri, Apr 09, 1999 at 09:26:51AM -0500, G . T . Francisco wrote:
> On Fri, Apr 09, 1999 at 06:53:38AM -0500, Olmy said:
> > Personally, I just do it in vi:
> > 
> > :%s/controlvcontrolm/controlv<space>/g
> > 
> > All I'm doing here is taking the Control M's and replacing it with a
> > space.
> > 
> 
> In vi, you can also do a set fileformat=dos and then write the file.

more precisely, in 'vim' you can also...


===

From: Dale Lovelace <dale@redhat.com>
Date: Fri, 09 Apr 1999 11:44:41 -0400
Subject: Re: stripping the ^M 


On Thu, 08 Apr 1999 22:45:52 -0800  Ramon Gandia <rfg@nook.net>  wrote: 

> You are reinventing the wheel.  There is a utility program
> to do this, or the other way around.  Its called dos2unix
> and unix2dos or something like that.  I could not find them
> offhand, but I know they exist.  Usage is something like
> this:


  Both unix2dos and dos2unix packages are on contrib.redhat.com

===

From: Gene Wilburn <gwilburn@rom.on.ca>
Date: Sat, 10 Apr 1999 10:31:11 -0400 (EDT)
Subject: Re: stripping the ^M


On Thu, 8 Apr 1999, Ramon Gandia wrote:

> Cimarron Ryan wrote:
> > 
> > Just for kicks, I decided to try and strip the nasty ^M from windows/dos
> > text files using sed.
> 
> You are reinventing the wheel.  There is a utility program
> to do this, or the other way around.  Its called dos2unix
> and unix2dos or something like that.  I could not find them
> offhand, but I know they exist.  Usage is something like
> this:
> 
> prompt# dos2unix dosfile.txt unixfile.txt

A caution on this program. If you have Latin-1 or anything other than US
Ascii chars in your file, this program also converts the accented chars to
non-accented equivalents (at least it did in the last version I tried).
Not a desirable side effect.

Much safer to roll your own with a bit of sed or perl.

===

From: "Anthony E. Greene" <agreene@pobox.com>
Date: Fri, 09 Apr 1999 09:16:54 +0200
Subject: Re: stripping the ^M


At 00:46 1999-04-09 -0400, Cimarron Ryan wrote:
>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

I don't use sed, but carriage returns are generally represented by \r. So
try this:

$ sed -e s/\r//g filename

===

the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu