Re: awk question
Re: awk question
- Subject: Re: awk question
- From: "Mark J. Reed" <email@hidden>
- Date: Fri, 1 Dec 2006 14:58:48 -0500
On 12/1/06, John C. Welch <email@hidden> wrote:
17 "Security Update for Exchange 2000 Server (KB894549)" zeroDotZero
application 2005-10-7,13:45:34.0
While awk is a good choice in general for simple column-splitting
tasks, the complexity of dealing with quoted strings containing the
delimiter pretty much removes its advantages. You can still use awk,
but you wind up using it as a general purpose programming language
without taking advantage of the features that streamline normal awk
processing. There's nothing wrong with that, and it does have a nice
set of string manipulation functions and regex matching and that good
stuff. But my take is that if you're going to Write A Program(TM),
you should do it in a Real Programming Language(TM). Or at least one
that doesn't make assumptions about what you want to do with the input
that you have to turn around and violate.
Doesn't much matter which language. Out of the box, AppleScript
doesn't make it easy, but with Satimage it should be fairly
straightforward. Perl, Python, Ruby, Tcl, JavaScript if you have an
interpreter for it in the target environment - all will work.
The key is to split the string using a regular expression rather than
a simple delimiter string. For instance, this will work in Perl:
my @fields = ();
push (@fields, $1||$2) while (/"([^"]*)"|(\S+)/g)
The above should be translatable into the language of your choice.
Note that the order of the alternatives in the regex is significant.
--
Mark J. Reed <email@hidden>
_______________________________________________
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/mailman//archives/applescript-users
This email sent to email@hidden
References: | |
| >awk question (From: "John C. Welch" <email@hidden>) |