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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trailer Record

Status
Not open for further replies.

PatelRam

Programmer
Aug 20, 2003
87
US
I have source file like below

"position" file

HABCDEFDSKLKFSDFSDK <--- HEADER RECORD
217ABC1000,3000
217ABC1000,3000
218ABC1000,3000
217ABC1000,3000
218ABC1000,3000
218ABC1000,3000
217ABC1000,3000
217ABC1000,3000
TXYZ0008DATETIME <--- TRAILER RECORD (0008 is record count)


My target output file



HABCDEFDSKLKFSDFSDK <--- HEADER RECORD
217ABC1000,3000
217ABC1000,3000
217ABC1000,3000
217ABC1000,3000
217ABC1000,3000
TXYZ0005DATETIME <--- Trailer record (0005 is record count)



I have used following command

header -1 position > testfile
grep &quot;^217&quot; position >> testfile

I don't know how to get record count and update trailer record and appended to target file
test

If anybody has suggestion





 
Try something like this:
Code:
awk '
NR==1{print;next}
/^217/{++nr;print;next}
{t=$0}
END{printf &quot;%s%04d%s\n&quot;,substr(t,1,4),nr,substr(t,9)}
' /path/to/position >testfile

Hope This Help
PH.
 
something like this - a bit rought, but.......

awk -f patel.awk myFile.txt

#--------------------------- patel.awk

BEGIN {
count=1;
}

/^[A-Z].*/ && !block { block=1; print; next}
block==1 && (count % 5) {print}
!(count % 5) { print; block=2}
{count++}
/^[A-Z].*/ && block==2 { block=0; printf(&quot;%s%04d%s\n&quot;, substr($0,1,4), 5, substr($0,9))}


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
THANK YOU VERY VERY MUCH........................

IT WORKED IN FIRST SHOT...................

 
Can I ask you more thing about this code


awk '
NR==1{print;next}
/^217/{++nr;print;next}
{t=$0}
END{printf &quot;%s%04d%s\n&quot;,substr(t,1,4),nr,substr(t,9)}
' /path/to/position >testfile

I need the testfile created like testfile_12102003

and the date i have to fetch from trailer record.

the source file is

HABCDEFDSKLKFSDFSDK <--- HEADER RECORD
217ABC1000,3000
217ABC1000,3000
218ABC1000,3000
217ABC1000,3000
218ABC1000,3000
218ABC1000,3000
217ABC1000,3000
217ABC1000,3000
TXYZ000812102003 <--- Trailer record (12102003)

How do i do it ?

 
Something like this ?
Code:
awk '
NR==1{a[0]=$0;next}
/^217/{a[++nr]=$0;next}
{t=$0}
END{
 out=&quot;testfile_&quot;substr(t,9,8)
 for(i=0;i<=nr;++i) print a[i]>out
 printf &quot;%s%04d%s\n&quot;,substr(t,1,4),nr,substr(t,9)>out
}' /path/to/position

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top