Content-Type: |
text/plain; charset=UTF-8 |
Sender: |
|
Subject: |
|
From: |
|
Date: |
Tue, 18 May 2010 19:54:23 -0400 |
In-Reply-To: |
|
MIME-Version: |
1.0 |
Reply-To: |
|
Parts/Attachments: |
|
|
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]>
|
|
|