Mutiple output files single Input file 
Author Message
 Mutiple output files single Input file

% Ok, here is the requirement, I have got one input file and based on certain
% conditions in line(s) I need that line(s) to a redirected to a unique output
% file. No of output files is dependent on the data and is not constant.

You can have
 /Jehoshaphat/ { print >> "Rumpelstiltskin" }
 /mansion/ { print >> "yacht" }

The two >> mean to append to the file. One > means to write over
any existing file of the same name. There's a problem with this
if you could have any number of files to open -- most systems impose
a per-process limit of open files. You might need to keep track of which
files are being used and close one when you reach some limit.

For instance:

 /Jehoshaphat/ { printtofile($0,"Rumpelstiltskin") }
 /mansion/ { printtofile($0, "yacht") }
 function printtofile(what, where)
 {
   if (!(where in openfiles)) {
      if (filecount < 20) {
         openfiles[where] = ++filecount
         fnames[filecount] = where
      }
      # close the file that's been open the longest. A better but
      # more complicated approach is to close the file that was
      # least recently used (LRU)
      else {
         nextdelete = (nextdelete+1) % 20
         if (!nextdelete) nextdelete = 20
         close(fnames[nextdelete])
         delete openfiles[fnames[nextdelete]]
         openfiles[where] = nextdelete
         fnames[nextdelete] = where
      }
   }

   print what >> where
 }
--

Patrick TJ McPhee
East York  Canada



Sun, 29 Jul 2001 03:00:00 GMT  
 Mutiple output files single Input file

Quote:


>% Ok, here is the requirement, I have got one input file and based on
certain
>% conditions in line(s) I need that line(s) to a redirected to a unique
output
>% file. No of output files is dependent on the data and is not constant.

>You can have
> /Jehoshaphat/ { print >> "Rumpelstiltskin" }
> /mansion/ { print >> "yacht" }

>The two >> mean to append to the file. One > means to write over
>any existing file of the same name. There's a problem with this

-- snip --

To be clear about it, I think that one > means to overwrite the file on the
first attempt at writing to the filename. All subsequent attempts to write
to the same filename within the same run of the awk program append to the
file (i.e. behave as >>)

Cesar
--
Please remove the UPPERCASE characters from my e-mail address for the real
thing



Sun, 29 Jul 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Single file input ==> multi file output

2. newbie would like to break input file and output to separate files

3. Reading from input file writing to output file

4. sed: input file = output file

5. comparing an input file with an output file

6. with-input-from-file, with-output-to-file

7. with-input-from-file, with-output-to-file

8. TEMPORARY FILE during input and output??

9. open-{input,output}-file

10. Text file input/output

11. reading input files and then output

12. input/output file question

 

 
Powered by phpBB® Forum Software