Re: [OT] UNIX heads; can I do this?
Re: [OT] UNIX heads; can I do this?
- Subject: Re: [OT] UNIX heads; can I do this?
- From: "Steven D. Majewski" <email@hidden>
- Date: Wed, 13 Jun 2007 16:35:46 -0400
On Jun 13, 2007, at 3:54 PM, Bill Briggs wrote:
I want to take a text file with Mac (cr) line endings and change to
UNIX (lf) line endings (eventually I'm piping it to awk, which
needs the lf or it sees it all as one line).
So far I can find and clobber all of the cr's, but can't get it to
replace with lf's. I'm doing this (where you get the ^M by holding
Ctrl and pressing V and Return in sequence). Note that the replace
field is empty in the following.
sed -e 's/^M//g' t.txt | cat > b.txt
I've tried replacing with \f, \n, \x0A, and nothing seems to work.
I can't seem to determine the magic sauce to get that line feed
inserted.
Then again, maybe it's not possible to do that with sed, but I
can't see why not.
Frustrating -- isn't it ?
( This is not really spelled out in the docs, but is sort of
implied by putting together a couple of statements in the
man page with knowledge of how the shell works ... plus the
fact that nothing else really works here! ;-)
This should(*) work in sed:
sed -e 's/\r/\
/g'
i.e. within the single quote, for the substitution character
type a backslash, followed by the return key(*), and continue
the rest of the command on the next line.
Note that \r as well as \n and other escapes work in the input
pattern space but not in the output pattern space.
[ (*) This may depend on stty settings or other things that
affect mappings, but return key should typically be sending
(x0A) newline character code. Typing a Control-J should
also work and probably works more reliably under different
settings / mappings. If you are typing this sequence in an
editor, that opens up another bunch of variant possibilities. ]
But the "standard" way to do this sort of substitution is with 'tr'
which WILL take symbolic escape codes in either the 'to' or the 'from'
space:
tr '\r' '\n'
-- Steve Majewski / UVA Alderman Library
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden