Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Dec 2002 08:01:04 -0600
From:      D J Hawkey Jr <hawkeyd@visi.com>
To:        Warren Block <wblock@wonkity.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: tool/method to convert DOS line endings to UNIX line endings
Message-ID:  <20021204080104.A56240@sheol.localdomain>
In-Reply-To: <Pine.BSF.4.21.0212040557280.13865-100000@wonkity.com>; from wblock@wonkity.com on Wed, Dec 04, 2002 at 06:05:59AM -0700
References:  <200212040153.gB41rF154346@sheol.localdomain> <Pine.BSF.4.21.0212040557280.13865-100000@wonkity.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Dec 04, at 06:05 AM, Warren Block wrote:
> 
> On Tue, 3 Dec 2002, D J Hawkey Jr wrote:
> 
> > In article <Pine.BSF.4.21.0212031550360.12062-100000_wonkity.com@ns.sol.net>,
> > 	wblock@wonkity.com writes:
> > > It's a bit easier if you let Perl do the heavy lifting:
> > > 
> > > perl -pi -e 's/\r//g' file-to-convert
> > 
> > Even easier (and "lighter") if you ditch the perl:
> >    sed -e 's/\r//g' input >output
> 
> Unfortunately, that doesn't work because BSD sed doesn't understand \r
> (it should, IMO, but it doesn't).  It can work if you put an actual CR
> in there...

Ack. Looks like you're right, and I agree with you. If "[2addr]l" can output
'\r', "[2addr]s/regex/repl/flags" ought to understand "\r". I have to wonder
how many times I may have been bitten by this mis-feature.  ;-,

This'll work though:
    sed -e 's/[[:cntrl:]]$//g'

> > I like the tr(1) conversion too, but I always seem to think in terms of
> > sed(1) and awk(1).

And if that sed(1) solution is still "too loose", the tr(1) solution reduces
"[[:cntrl:]]" to just the CR character.

> I've been making an effort to use Perl for this type of thing, because
> it usually saves me time.  When a shell script turns out later to need
> strong string processing or any of the other stuff that Perl is good at
> but is non-trivial in a shell script, I don't need to rewrite it if it's
> already in Perl.  And many scripts that are trivial in Perl (like the
> one above) can be non-trivial for csh or sh.

Agreed, in principle, but with caveats. Perl isn't available in single-user
mode without mounting /usr (or /usr/local on other OSes), and IIRC, perl
won't be in the base for FreeBSD 5.0 (something about "miniperl"?). Outside
of FreeBSD, perl may not be available at all. I try to use the tools of a
base installation of any OS for these "quick-n-dirty" things, if just to
know that I can.

And I guess there's enough frugalness(?) in me to opt for the lighter weight
tool when it's all that's needed. Nice to have so many options, though!

> -Warren Block * Rapid City, South Dakota USA

See Ya,
Dave

-- 
  ______________________                         ______________________
  \__________________   \    D. J. HAWKEY JR.   /   __________________/
     \________________/\     hawkeyd@visi.com    /\________________/
                      http://www.visi.com/~hawkeyd/


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




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