MACSCRPT Archives

May 2010

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Mark J. Reed" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 18 May 2010 19:54:23 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (24 lines)
On Tue, May 18, 2010 at 7:44 PM, Mark J. Reed <[log in to unmask]> wrote:
> sed -E -e "$(echo -e 's/\r\n?/\n/g')" dosfile >mytext

Actually, I take it back, that won't work.  For one thing, echo turns
the \n into a literal newline which sed doesn't like; for another, it
wouldn't match anyway, since sed does its matching on a line-by-line
basis and never actually sees the newline character for purposes of
pattern matching.

To get rid of CRs before LFs, you can do this:

sed "$(echo -e 's/\r$//')"

To turn bar CRs into LFs, you can do this:

sed "$(echo -e 's/\r/\\\n/g')"

But you have to know which one is needed.  Perl special-cases the
matching of newline at the end of a string so you can write one line
to handle both cases.

-- 
Mark J. Reed <[log in to unmask]>

ATOM RSS1 RSS2