[comp.unix.questions] Setting the field seperator in awk

palkovic@linac.fnal.gov (John A. Palkovic) (10/19/90)

I would like to set the field separator in awk(1) so that in addition
to the default separator I could include a comma with white space,
i.e. 

	a, b
	a,b
	a 	,	b

as well as the default case, which is just white space. I'm afraid
that I don't understand regular expressions well enough to do this
since all my attempts so far have failed. 

What is the regexp for the default field separator in awk(1)?

arnold@audiofax.com (Arnold Robbins) (10/20/90)

In article <2453@linac.fnal.gov> palkovic@linac.fnal.gov (John A. Palkovic) writes:
>I would like to set the field separator in awk(1) so that in addition
>to the default separator I could include a comma with white space,
>as well as the default case, which is just white space.

You have to have either nawk or gawk for this; old awk won't work.  Assuming
you have nawk or gawk, all you need is

	FS = "[ \t,]+"

This says that fields are separated by runs of one or more blanks, tabs,
or commas.  The (current) AWK language says that if FS == " ", it's a
special case, and is treated as if FS were "[ \t]+", i.e. runs of blanks
and/or tabs.
-- 
Arnold Robbins				AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #200 / Marietta, GA. 30067     | exponentially in the
INTERNET: arnold@audiofax.com Phone:   +1 404 933 7612 | number of children.
UUCP:	  emory!audfax!arnold Fax-box: +1 404 618 4581 |   -- Miriam Robbins