[comp.unix.questions] ``Stupid awk'' question

piet@cs.ruu.nl (Piet van Oostrum) (10/11/89)

In article <DMAUSTIN.89Oct10145918@vivid.sun.com>, dmaustin@vivid (Darren Austin) writes:
 `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
 `
 `so apparently it is running out of file descriptors.  I thought
 `that would be taken care of by using the "close" function.  Am I
 `using it incorrectly, or am I doing something else wrong?  Is

I've never heard of close. That must be one of those modern things.

 `there a better way to do this with other tools?
 `
1. Let awk generate a shell script, and run that through sh.

 (current == $2) {print}
 (current != $2) {if (current) print "Some-funny-eof-sequence";
		current=$2;
		print "cat << Some-funny-eof-sequence >>"current".summary";}
 END { print "Some-funny-eof-sequence"}

2. Use Larry Wall's perl.
-- 
Piet van Oostrum, Dept of Computer Science, University of Utrecht
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht,  The Netherlands.
Telephone: +31-30-531806      Internet: piet@cs.ruu.nl
Telefax:   +31-30-513791      Uucp: uunet!mcsun!hp4nl!ruuinf!piet