• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: awk question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: awk question
      • From: "John C. Welch" <email@hidden>
    • Re: awk question
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Re: awk question (From: "Mark J. Reed" <email@hidden>)
 >Re: awk question (From: "John C. Welch" <email@hidden>)

  • Prev by Date: ctrl m question
  • Next by Date: Re: ctrl m question
  • Previous by thread: Re: awk question
  • Next by thread: Re: awk question
  • Index(es):
    • Date
    • Thread