I am searching for a simpler way to parse input into separte files.
The input, where the fields are separated by a pipe, looks like this:
1|Barron's|\n* Location: PERIODICAL|\n* Location: v.74 (1994)-v.80 (2000) Micro
fiche\n* Location: RESERVES\n* Location: Latest issues located in Periodical Res
erves.
2|0047-8318|Ms|\n* Location: PERIODICAL|\n* Location: v.1 (1972)-v.8 (1980) Bou
nd\n* Location: v.9 (1980)-v.18 (1989) Microfiche
2|0047-8318|Ms|\n* Location: PERIODICAL|\n* Location: v.1 (1990/1991)-v.9 (1999/
1999) Bound\n* Location: v.1 (1990/1991)-v.4 (1994) Microfiche\n* Location: La
test issues located in Current Periodicals.
I'm writing a Bourne shell script that includes the following awk instructions in order to place groups of records into separate files for specific processing. I am using groupid from the first field to parse them into files. Since this file is small, I can do this, but if there were many groups and many records this would become cumbersome.
The awk instructions are:
awk -F"|" '{if ($1 == 1) print $0}' fixfieldawk.out > barrons
awk -F"|" '{if ($1 == 2) print $0}' fixfieldawk.out > ms
awk -F"|" '{if ($1 == 3) print $0}' fixfieldawk.out > lancet
awk -F"|" '{if ($1 == 4) print $0}' fixfieldawk.out > currentbio
awk -F"|" '{if ($1 == 5) print $0}' fixfieldawk.out > japysiology
awk -F"|" '{if ($1 == 6) print $0}' fixfieldawk.out > jquarterly
awk -F"|" '{if ($1 == 7) print $0}' fixfieldawk.out > libraryj
This is so repetitive and I was wondering if anyone might know of a better way.
Thanks