Single file input ==> multi file output 
Author Message
 Single file input ==> multi file output

I have a single text file consisting of the following
records. A new record starts with the line PTR:.

What I want to do is to split the data for each record
into two separate files.

For example, for the record starting with PTR: BRR1
I wish to create two output files:
BRR1.output1
BRR1.output2

BRR1.output1 contains all the information up to the
line starting with Description:

BRR1.output2 contains all the information from
Description: onwards.

How would I accomplish this using awk?

PTR: BRR1
Title: This is the title line for the first problem.

Reproducible: yes

Description:
...
...
...
...

PTR: BRR2
Title: This is the title line for the second problem.

Reproducible: no

Description:
...
...
...

--
-------------------------------------------------------------------------

Configuration Management Engineer       Tel:   408-764-9496
Fujitsu Network Communications          Fax:   408-764-9365
5200 Patrick Henry Drive,              
Santa Clara, CA 95054
-------------------------------------------------------------------------



Wed, 15 Mar 2000 03:00:00 GMT  
 Single file input ==> multi file output

Quote:

> I have a single text file consisting of the following
> records. A new record starts with the line PTR:.

> What I want to do is to split the data for each record
> into two separate files.

> For example, for the record starting with PTR: BRR1
> I wish to create two output files:
> BRR1.output1
> BRR1.output2

> BRR1.output1 contains all the information up to the
> line starting with Description:

> BRR1.output2 contains all the information from
> Description: onwards.

Something like the following (untested) code should do the trick:

/^PTR/ { if(f1!="") {close f1; close f2}
         f1 = $2 ".output1"
         f2 = $2 ".output2"
         do1 = 1; do2 = 0
       }
/^Description/ { do1 = 0; do2 = 1 }
do1    { print $0 > f1; next }
do2    { print $0 > f2 }

I use two switches, do1 and do2, to handle the case of miscellaneous
input before the first PTR record. If you are sure there is no such
possibility, remove all references to do2.
--
Bob Stearns
University of Georgia

(706)542-5110



Fri, 17 Mar 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Mutiple output files single Input file

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. .cob files >>> .exe files

9. Q: Multi file input for AWK

10. output multi regex match to file

11. how do i convert a multi column into a single column in the output in fortran

12. TEMPORARY FILE during input and output??

 

 
Powered by phpBB® Forum Software