Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Aug 1997 09:28:20 -0400 (EDT)
From:      Brian Clapper <bmc@WillsCreek.COM>
To:        questions@FreeBSD.ORG
Subject:   Re: Stripping ^M from llines?
Message-ID:  <199708301328.JAA04754@current.willscreek.com>
In-Reply-To: <49570184@toto.iv>

next in thread | previous in thread | raw e-mail | index | archive | help

--zh3oQklXc94K4Oncr3b8iJWCMlJd6gHuC/WSj8q/
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Robert Chalmers wrote:

> Anyone got a handy program for stripping the ^M from text
> lines in fbsd?

Converting DOS files to UNIX (which is what I assume you're doing) is only
a couple lines of perl.  What's more, you don't need to recompile them if
you want to take 'em someplace else (though you might need to edit the path
to the perl binary).

I've enclosed a dos2unix perl script and a unix2dos one.  I've used them
for years.
-----
Brian Clapper, bmc@WillsCreek.COM, http://WWW.WillsCreek.COM/
Got Mole problems?  Call Avogadro, 6.02 E23.


--zh3oQklXc94K4Oncr3b8iJWCMlJd6gHuC/WSj8q/
Content-Type: text/plain
Content-Description: dos2unix
Content-Disposition: inline;
        filename="dos2unix"
Content-Transfer-Encoding: 7bit

#!/usr/bin/perl -pi
#
# Convert DOS text file to Unix file format.  Conversion is done in-place.
#
# Usage: dos2unix dosfile ...

print STDERR "Converting \"$ARGV\" ...\n" if (eof || ($. == 0));
s/\015$//;                      # strip ^M from end of line.
s/\032$//;                      # strip ^Z if we see it (which'll be at EOF).

--zh3oQklXc94K4Oncr3b8iJWCMlJd6gHuC/WSj8q/
Content-Type: text/plain
Content-Description: unix2dos
Content-Disposition: inline;
        filename="unix2dos"
Content-Transfer-Encoding: 7bit

#!/usr/bin/perl -pi
#
# Convert Unix text file to DOS file format.  Conversion is done in-place.
#
# Usage: unix2dos unixfile ...

print STDERR "Converting \"$ARGV\" ...\n" if (eof || ($. == 0));
s/$/\015/;                      # tack on ^M
s/\n/\n\032/ if (eof);          # DOS ^Z at end of file.


--zh3oQklXc94K4Oncr3b8iJWCMlJd6gHuC/WSj8q/--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199708301328.JAA04754>