[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
awk field separator
- Subject: awk field separator
- From: arnold at infographix.infographix.com (Arnold D. Robbins)
- Date: Thu, 22 Feb 1996 17:59:35 -0500
> Is there a way in awk to specify multiple field separators? Like FS =
> ";" | ":" | "\" I know this doesn't work, I just wanted to show what I'm
> trying to accomplish. BTW, FS=";:\" doesn't work B/C it thinks I mean
> the entire string ";:\". Has anyone tackled a problem like this before.
Using a modern awk (nawk, gawk, mawk), FS can be any regular expression.
The use of [..] as pointed out works. The \ can be included too
BEGIN { FS = "[;:\\\\]" }
...
The double backslashing is a pain though. You type two for every one that
gawk has to deal with. Internally, the string becomes
"[:;\\]"
And then when gawk processes this as a regex, it uses the three literal
characters `:', `;', and `\' in the brackets.
This is discussed in a few places in the 3.0.0 gawk manual.
Arnold Robbins InfoGraphix (Star Imaging LLC, dba)
Phone: +1-404-523-4944 250 Williams Street, Suite 1120, Atlanta, GA 30303
Fax: +1-404-523-4882 E-mail: arnold.robbins at infographix.com
"Oh! Look at all those zeros!" --- Chana Robbins, Age 3.5