I wrote (in part):
I've trying to run a program containing a rather complex awk script (I
didn't write it, so I can't really explain how it's doing what it does).
Said script works on AIX, HPUX, and IRIX, but not on DU (3.2G _or_ 4.0+).
Are there any known differences between Digital's awk and everyone else's?
Is POSIX biting me again?
Thanks to Michael Crowley, who suggested using "oawk" (which does the
trick!), and Berry Kercheval, who explained that DU's awk is really doing
the Right Thing. Here's his explanation.
The first line
BEGIN { FS="#" ; RS=">" }
happens before any records are read, of course, and says "Make the field
separator be the "#" string and the record separator the ">" string".
(Default values for these are "whitespace" and "newline" respectively)
In the case of Solaris (and presumably AIX, HPUX and IRIX, but I didn't test
them) your script behaves as you would expect, and if you run this program:
====
awk 'BEGIN { FS="#" ; RS=">" }
{
print ">> ", $0, "<<"
for(i=1; i<NF; i++) printf("F%d: %s\n", i, $i);
}
====
Then you get each *record* enclosed in >> << and each field in each record
printed with Fn:
Looking at your data, we'd expect this entire file to be one record, with
fields being the stuff between '#'s. When I run it on our DU4.0 machine i
get
====
>> <<
>> northstar.dartmouth.edu #Dartmouth College, Project Northstar
129.170.16.43 #cygnusx1.dartmouth.edu
129.170.16.205 #beehive.dartmouth.edu
129.170.24.37 #andromeda.dartmouth.edu
129.170.24.115 #horsehead.dartmouth.edu
<<
F1: northstar.dartmouth.edu
F2: Dartmouth College, Project Northstar
129.170.16.43
F3: cygnusx1.dartmouth.edu
129.170.16.205
F4: beehive.dartmouth.edu
129.170.24.37
F5: andromeda.dartmouth.edu
129.170.24.115
====
Which has an empty record, then the entire file as we expect, then the fields:
notice that fields 3,4, and 5 have an embedded newline.
When I run it on solaris (where *your* script works as you say you expect)
I get this:
====
>> <<
>> northstar.dartmouth.edu #Dartmouth College, Project Northstar
129.170.16.43 #cygnusx1.dartmouth.edu
129.170.16.205 #beehive.dartmouth.edu
129.170.24.37 #andromeda.dartmouth.edu
129.170.24.115 #horsehead.dartmouth.edu
<<
F1: northstar.dartmouth.edu
F2: Dartmouth College, Project Northstar
F3: 129.170.16.43
F4: cygnusx1.dartmouth.edu
F5: 129.170.16.205
F6: beehive.dartmouth.edu
F7: 129.170.24.37
F8: andromeda.dartmouth.edu
F9: 129.170.24.115
F10: horsehead.dartmouth.edu
====
Whoa! The fields are being broken at the '#' characters AND AT NEWLINES.
Pat Wilson
paw_at_dartmouth.edu
Received on Fri Mar 20 1998 - 17:26:10 NZST