Awk Field Separators

Randal Schwartz merlyn at iwarp.intel.com
Wed Aug 22 15:43:30 AEST 1990


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?
| I would like to specify to an Awk program to treat single spaces as well
| as bars as field separators so that a string such as :
| 
| 12 12 12 34|34|34
| 
| will be said to have 6 fields.  I've tried to create a regular expression
| to handle both cases but it hasn't been working.

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

...
while (<>) {
	@arr = split(/[ |]/);
	# $arr[0] .. $arr[5] now has the six fields you asked for
	...
}
...

Just another Perl [book] hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/



More information about the Comp.unix.questions mailing list