Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!ogicse!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: Awk Field Separators Message-ID: <1990Aug22.054330.24911@iwarp.intel.com> Date: 22 Aug 90 05:43:30 GMT References: <3729@se-sd.SanDiego.NCR.COM> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: comp.unix.questions Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 28 In-Reply-To: cubbage@se-sd.SanDiego.NCR.COM (Sharon Cubbage) In article <3729@se-sd.SanDiego.NCR.COM>, cubbage@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@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/