Awk Field Separators

Norman Joseph norm at oglvee.UUCP
Thu Aug 23 23:55:12 AEST 1990


In <1990Aug22.054330.24911 at iwarp.intel.com> merlyn at iwarp.intel.com (Randal Schwartz) writes:

>In article <3729 at se-sd.SanDiego.NCR.COM>, cubbage at se-sd (Sharon Cubbage) writes:
>| Does anybody know how to specify more than one field separator in Awk?
>| [...] so that a string such as :
>| 
>| 12 12 12 34|34|34
>| 
>| will be said to have 6 fields. [...]

>There's no easy way to handle it in plain Awk.  (Alright everyone, what's
>the next phrase... come along now...) Get Perl.
>[...]

What's so hard about:

        BEGIN { FS = "[ ]|[|]" }

other than the fact that it requires the newer version of awk, as
distributed with 5.3 (on this Altos, running 5.3, it's called ``nawk'').
This makes single blanks and single bars field separators.  If you
want to allow multiple spaces or bars, use "[ ]+|[|]+".  If you want
to collapse multiple occurences of bars or spaces as a single field
separator use "[ |]+".

>Just another Perl [book] hacker,

Just another Perl wannabe (Mebbe someday when I have the time...)  :-)
-- 
Norm Joseph                                      cgh!amanue!oglvee!norm at dsi.com
  Oglevee Computer Systems, Inc.                {pitt,cgh}!amanue!oglvee!norm
      "Shucking Usenet oysters in pursuit of a pearl."  --  Bill Kennedy



More information about the Comp.unix.questions mailing list