Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!bink From: bink@aplcen.apl.jhu.edu (9704) Newsgroups: comp.unix.questions Subject: Re: Stupid awk question Summary: "bs" works well for splitting files this way too Message-ID: <3444@aplcen.apl.jhu.edu> Date: 12 Oct 89 02:07:49 GMT References: <3731@ethz-inf.UUCP> Reply-To: bink@aplcen.apl.jhu.edu (Greg Ubben 301-421-9704) Organization: The Johns Hopkins University, Baltimore MD Lines: 36 In article <3731@ethz-inf.UUCP> wyle@ethz.UUCP (Mitchell Wyle) writes: > In article 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@aplcen.apl.jhu.edu ...!uunet!mimsy!aplcen!bink