Re: awk question
Re: awk question
- Subject: Re: awk question
- From: "Mark J. Reed" <email@hidden>
- Date: Fri, 1 Dec 2006 17:28:16 -0500
On 12/1/06, John C. Welch <email@hidden> wrote:
Sigh...I figured I'd need perl, but I was hoping. Booger. ah well, such is
life
I don't really understand willingness to use awk but reluctance to use
Perl. If you'd prefer a different language, the above is readily
translated into Python or Ruby or Tcl.
It's slightly less-readily translated into awk, because awk doesn't
support capturing the substrings matched by parts of a regular
expression, but it's still doable:
<datafile awk '
{
fnum = 1
while (match($0,/"[^"]*"|[^ ][^ ]*/))
{
field[fnum++] = substr($0, RSTART, RLENGTH) "'"
$0 = substr($0, RSTART + RLENGTH);
}
for (i=1; i<fnum; ++i)
{
print i": "field[i]
}
}'
In place of the for loop printing out the fields you can do whatever
you want with them...
--
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