Grab records/write to file in AWK 
Author Message
 Grab records/write to file in AWK

Hello, Group.  I'm very new to Awk, so forgive me if this is a basic question.
I have a file that looks like the following (actually it has a lot of other
characters, but I wanted to keep it short in here):

ISA*Record number 1
GS*
PID*
EA*
IEA*End of Record number 1
ISA*Record Number2
GS*
IEA*End of Record number2

Each time a new ISA shows up, this is a new record that I need to have written
out to a unique filename (would I use filename.$$).  I need from ISA to EA, but
each ISA to EA range being written out to its own unique filename.  So, I
looked in a book and noticed that I could do awk '/^ISA/,/^IEA/' filename, but
can you help me figure out how to write each ISA-IEA range out to a different
filename?

Please do me a favor and post your response here instead of directly to me.
I'm able to see the newsgroup, but not my personal messages from work.  Thanks.



Mon, 23 Jul 2001 03:00:00 GMT  
 Grab records/write to file in AWK


Quote:
(SJacksonII) writes:
>. . . I have a file that looks like the following . . .

>ISA*Record number 1
>GS*
>PID*
>EA*
>IEA*End of Record number 1
>ISA*Record Number2
>GS*
>IEA*End of Record number2

>Each time a new ISA shows up, this is a new record that I need to
>have written out to a unique filename (would I use filename.$$).
>I need from ISA to EA, but each ISA to EA range being written out
>to its own unique filename.  So, I looked in a book and noticed that I
>could do awk '/^ISA/,/^IEA/' filename, but can you help me figure out
>how to write each ISA-IEA range out to a different filename?

awk '/^ISA/{o="output." ++n}
  /^ISA/,/^IEA/{print>o}
  /^IEA/{close(o)}' filename

If you don't want output.11 to show up before output.2 in sorted directory
listings, use  out=sprintf("output.%03d",++n)  instead.



Mon, 23 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. deleting records in a file using AWK, SED, or kshell

2. writing records to files

3. Writing Datalog Files with record length

4. Writing records to a .DBF IV file

5. Writing Record Structures to a File

6. Writing records MS Access records from LabVIEW

7. sed/awk - grabbing column/pos help!!

8. Grabbing Highlighted Record from Browse

9. Outputting info from awk and using the info to name the awk output file

10. Grabbing content written to an MS-DOS window

11. grabs and problems with grabs: they don't seem to work

12. process only last record using awk

 

 
Powered by phpBB® Forum Software