Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] UNIX heads; can I do this?



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:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Email Change because of SPAM... (Sorry for the RESEND) (From: Don Wieland <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.