Stupid awk question
David Goodenough
dg at lakart.UUCP
Tue Oct 17 07:24:49 AEST 1989
dmaustin at vivid.sun.com (Darren Austin) sez:
> Hi all,
> I am trying to split up a large output file into several
> smaller files. The smaller files are named after the value in
> the second field. I tried using the following simple awk script,
>
> (current == $2) {print > current".summary"}
> (current != $2) {close(current".summary");current=$2;print > current".summary";}
>
> but it fails with
>
> awk: too many output files 10
Try this:
-------------------------------------------
#! /bin/sh
awk '{
print "echo '"'"'" $0 "'"'"' >> " $2 ".summary"
}' | sh
-------------------------------------------
Only problem is, it tends to chew up process id's. Oh well ..... Also it
appends, so you might have a problem if you wanted to initialise at the
start of each run. But you get the general idea. Also has the advantage
of not getting into trouble if your input file hasn't been sorted (i.e.
$2 records can come in any order)
--
dg at lakart.UUCP - David Goodenough +---+
IHS | +-+-+
....... !harvard!xait!lakart!dg +-+-+ |
AKA: dg%lakart.uucp at xait.xerox.com +---+
More information about the Comp.unix.questions
mailing list