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: "Jim DeVona" <email@hidden>
- Date: Thu, 14 Jun 2007 01:06:46 -0400
On 6/13/07, Bill Briggs <email@hidden> 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).
Perhaps it is not appropriate in your case, but this is also trivial
in Tcl, which by default translates all input line endings to \n (lf):
puts [read -nonewline stdin]
To output something other than the platform default line ending (\n on
Mac OS X), or to be more explicit about what you're doing, use
fconfigure to set the output line ending:
fconfigure stdout -translation crlf
puts stdout [read -nonewline stdin]
You can also specify cr or lf as the -translation.
Anyway, you could save the following as convert.tcl:
#!/usr/bin/env tclsh
fconfigure stdout -translation lf
puts stdout [read -nonewline stdin]
And then use it in your pipeline like this:
convert.tcl < t.txt | awk ...
To convert the \r formatted t.txt to \n line endings and pipe it along to awk.
Just one more way to peel the cat, with perhaps a bit simpler syntax
than some of the sed solutions.
Be well,
Jim
_______________________________________________
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