Stupid awk question
9704
bink at aplcen.apl.jhu.edu
Thu Oct 12 12:07:49 AEST 1989
In article <3731 at ethz-inf.UUCP> wyle at ethz.UUCP (Mitchell Wyle) writes:
> In article <DMAUSTIN.89Oct10145918 at vivid.sun.com> Darren Austin writes:
>
> >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,
> > [...]
> >but it fails with
> >awk: too many output files 10
>
> [...]
> sort +0 | awk '[SCRIPT BY TONY O'HAGAN DELETED]' | /bin/sh
> [...]
If you don't have access to the new AWK, but do have the "bs" command
(mini-language) on your machine, I've found it also works well for
splitting a file into subfiles which are named by a field of the input.
The following bs program should solve Mr. Austin's problem in one process:
#!/bin/bs
# Split the input into files named by the 2nd field.
outfile = ""
while ?(line = get)
match (line, "[^\t ]*[\t ]*\([^\t ]*\)")
if mstring(1) != outfile open ("put", outfile=mstring(1), "w")
put = line
next
run
(The open seems to automatically close the previous file)
I don't know how portable this is; bs is available in System V.2 anyway.
Type ^N now for a way to do this in 1 line of PERL, by Mr. Schwartz... ;-)
-- Greg Ubben
bink at aplcen.apl.jhu.edu
...!uunet!mimsy!aplcen!bink
More information about the Comp.unix.questions
mailing list