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!

Creating File names inside script

Status
Not open for further replies.
Aug 3, 2001
29
US
I am splitting information inside a script and want to establish a file name from data read. Right now I have a script that separates and fills a file but the file name is one I create. In the file I am reading the 2nd text line(record) has the 9th field that I want to id the file.
I am beating my brains trying to figure this one out.

here is a sample of the script I am using.
It takes a file and creates single files for each ISA/IEA encountered.


/^ISA/ && OUTFILE == "" {
OUTFILE = "ACK997X"sprintf("%03d",outnum++)".999"
}
OUTFILE != ""{
print > OUTFILE
}
/^IEA/ && OUTFILE != ""{
close(OUTFILE)
OUTFILE=""

In the 2nd text line, it always starts with a "GS" and the 9th field always has a value
Example
ISA*00* *00* *01*003897733 *02*HBGI *000210*072
8*U*00300*000021127*0*P*^
GS*FA*COMPAQSTS*HBGI*000210*0728*21127*X*003040
ST*997*0001
AK1*QM*14975
AK9*A*1*1*1
SE*4*0001
GE*1*21127
IEA*1*000021127

In the above I want to create a file id "ACK997X"+"3040".suffix

Thanks for any assistance.


Len
 
I am using this in a RS6000 Aix environment.
The application id is splitxxx.awk

One other thing I have a question on
since I pass the file into this script.
Is the file name available to use when the line
print > outfile is in play ???

I wonder if I need to set a filename var in the Begin ??

Thanks,

Len
 
hi,
as far as I can recall, I've posted this solution for the previous thread.

The output file name ["OUTFILE"] is derived. I odn't quite understand what needs to be achieved though....

To answer your second question - the name fo the currently processed file is available within awk by the reference to the internal variable FILENAME. The variable is assigned appropriate filename value implicitly. vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Vgersh99, yes you answered last week.

I got the file to split with the script you sent.

So when you say the current processing file is refered by the internal variable FILENAME. Can I pass it into the awk -f line to have it be the file name that is generated by the awk script ????
Am I clear on that???

File with data is sent to the awk script .
It parses data into individual files.
Before it was file names =file +xxx(incrementing)with txt suffix.
I want to be able to name the files with the processing file name + xxx(incrementing) suffix.


thanks,


Len
 
/^ISA/ && OUTFILE == &quot;&quot; {
OUTFILE = FILENAME sprintf(&quot;%03d&quot;,outnum++) &quot;.999&quot; vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top