Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need direction, moving data from inside file to a separate file

Status
Not open for further replies.
Aug 3, 2001
29
US
I have many records in file but these records are associated with each other : example a1,a2,a3,a4,a5,a6,etc... then a1,a2,a3,a4,a5,a6,etc... then a1,a2,a3,a4,a5.... and so on. I want to be able to read through the file and move a1,a2,a3,a4,a5,a6,etc... into its own file. then read on and move the next a1,a2,a3,a4,a5 into its own file.

Appreciate any guidance. I am still a rookie bumping my head writing this.


Thanks, again

Len
 
i think this is 'comprehensible' ??? vox clamantis in deserto.
 
what does make ONE record to go to ONE file and the OTHER record to go to a diff. file? vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Let me clarify.

text file with data line by line in patterns {a1=1st line variable length, a2=2nd line variable length and so on for many lines last line in pattern will be a(xx)=1st three charcters (abc)....
I want to be able to read through and pull these lines out into another file.
then continue reading remaining lines that will begin and end like the above pattern.

Is that clear ????


Thanks,

Len
 
I think I understand some of it, but not all it.

Pls post a sample data file and desired output - it might be easier that way. vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
File has data like this

ISA*text*text*text*....
GS*text*text*....
ST*text*text*....
AK1*text*text*.....
AK9*text*text*....
SE*text*text*.......
GE*text*text*......
IEA*text*text*text*text*....
ISA*text*text*text*....
GS*text*text*....
ST*text*text*....
AK1*text*text*.....
AK9*text*text*....
SE*text*text*.......
GE*text*text*......
IEA*text*text*text*text*....
ISA*text*text*text*....
GS*text*text*....
ST*text*text*....
AK1*text*text*.....
AK9*text*text*....
SE*text*text*.......
GE*text*text*......
IEA*text*text*text*text*....

all text is variable could be numeric/alpha.
I am trying to get the data from ISA to IEA and put it into another file. Then repeat the ISA to IEA into another file and so on...

Thanks for the patience and assistance

Len
 
The files will be named &quot;fileNNN.txt&quot; where NNN will be incremented sequentially for every 'block'

nawk -f mySplitter.awk myTextFile.txt

#--------- mySplitter.awk
BEGIN {outnum=0}

/ISA/ && OUTFILE == &quot;&quot; {
OUTFILE = &quot;file&quot; sprintf(&quot;%03d&quot;,outnum++) &quot;.txt&quot;
}
OUTFILE != &quot;&quot; {
print >OUTFILE
}
/IEA/ && OUTFILE != &quot;&quot; {
close(OUTFILE)
OUTFILE=&quot;&quot;
}
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Vlad
The script worked beautifully.
Thanks for the assistance.

I appreciate all the help I get on this forum.

Question: I am reading script pgm in 24hrs but is there anything else out there to educate me ????


Len
 
Glad I could help.

All depends on your level of expertise.
Search Google for shell/sed/awk/unix FAQs, check the FAQs on this forum site.

Here are a couple of links to start you with:


Enjoy

vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top