[comp.unix.wizards] Redirecting output in AWKREAD/NEW/FOLLOWUP

cszohagan@qit.edu.au (11/05/88)

In article <1988Oct5.233609.15321@utzoo.uucp>, henry@utzoo.uucp (Henry Spencer) writes:
> In article <816@mergvax> rkxyv@mergvax (Rob Kedoin) writes:
>>I am trying to use AWK to split one file into many formatted, smaller files.
>>The problem I am having is that I cannot output to more than 10 files...
>  
> Well, it won't help you right now, but the long-term fix is to complain
> to your software supplier and ask them to get rid of the silly limit.
> It's not that hard.

The limits are based on the number of file descriptors that can be open
at one time (usually small).  One way that I often get around this is
by writting something like this which splits up the input on the field $1 .

sort +0 |
awk '
{
	if (last != $1) {
		if (NR > 0) print "!XYZZY";
		print "cat > " $1 "<<!XYZZY";
		last = $1;
	}
	print;
}
END { if (NR > 0) print "!XYZZY"; }' | /bin/sh

	Tony O'Hagan			tonyo@qitfit.qitcs.oz

henry@utzoo.uucp (Henry Spencer) (11/08/88)

In article <1169@qit.edu.au> cszohagan@qit.edu.au writes:
>>>The problem I am having is that I cannot output to more than 10 files...
>> Well, it won't help you right now, but the long-term fix is to complain
>> to your software supplier and ask them to get rid of the silly limit.
>> It's not that hard.
>
>The limits are based on the number of file descriptors that can be open
>at one time (usually small)...

Nonsense.  The limits are based on the laziness and lack of foresight of
the implementor.  Dynamically allocating a limited resource (open file
descriptors) among a larger user population (awk's "open" files) is a
well-understood practice.  It's utterly trivial to do for files opened
for appending (">>"), since you don't even need to remember that the file
used to be open.  That's about a five-line change to awk.  For ">" opens, 
you do need to remember the name and the position in the file.  Big deal.
There *are* awk implementations which do this.  Tell your supplier to get
his act together.
-- 
The Earth is our mother.        |    Henry Spencer at U of Toronto Zoology
Our nine months are up.         |uunet!attcan!utzoo!henry henry@zoo.toronto.edu