dayankoven
Programmer
Fellow gurus,
I have the following situation. One flat file needs to be splitted into 2 based on a certain condition. The file come with the following format :-
A BWCIF abc 02022004061853
Drec1 abc abc abc abc abc cdef A
Drec2 abc abc abc abc abc cdef I
Drec3 abc abc abc abc abc cdef A
Drec4 abc abc abc abc abc cdef I
Drec5 abc abc abc abc abc cdef A
Drec6 abc abc abc abc abc cdef I
Drec7 abc abc abc abc abc cdef A
Drec8 abc abc abc abc abc cdef I
Drec9 abc abc abc abc abc cdef A
Drec10 abc abc abc abc abc cdef I
Drec11 abc abc abc abc abc cdef A
T 00011
I need to break this file into the following format :-
File A
A BWCIF abc 02022004061853
Drec1 abc abc abc abc abc cdef A
Drec3 abc abc abc abc abc cdef A
Drec5 abc abc abc abc abc cdef A
Drec7 abc abc abc abc abc cdef A
Drec9 abc abc abc abc abc cdef A
Drec11 abc abc abc abc abc cdef A
T 00006
File B
A BWCIF abc 02022004061853
Drec2 abc abc abc abc abc cdef I
Drec4 abc abc abc abc abc cdef I
Drec6 abc abc abc abc abc cdef I
Drec8 abc abc abc abc abc cdef I
Drec10 abc abc abc abc abc cdef I
T 00005
I have the following syntax to help split the file :-
cat abc| awk 'substr($1,1,1)~/A/ {print $0}' > A_file
cat abc| awk 'substr($NF,length($NF),1)~/A/ {print $0}' >> A_file
cat abc| awk 'substr($1,1,1)~/T/ {print $0}' >> A_file
cat abc| awk 'substr($1,1,1)~/A/ {print $0}' > I_file
cat abc| awk 'substr($NF,length($NF),1)~/I/ {print $0}' >> I_file
cat abc| awk 'substr($1,1,1)~/T/ {print $0}' >> I_file
The problem i have now is that i don't know how to re-create the trailer record(T) based on the new record count.It should show 5 and 6 respectively for the I file and the A file respectively. The syntax above just shows the old record count which is 11. Can someone please help me with this.
Thanks in advance for all the help.
I have the following situation. One flat file needs to be splitted into 2 based on a certain condition. The file come with the following format :-
A BWCIF abc 02022004061853
Drec1 abc abc abc abc abc cdef A
Drec2 abc abc abc abc abc cdef I
Drec3 abc abc abc abc abc cdef A
Drec4 abc abc abc abc abc cdef I
Drec5 abc abc abc abc abc cdef A
Drec6 abc abc abc abc abc cdef I
Drec7 abc abc abc abc abc cdef A
Drec8 abc abc abc abc abc cdef I
Drec9 abc abc abc abc abc cdef A
Drec10 abc abc abc abc abc cdef I
Drec11 abc abc abc abc abc cdef A
T 00011
I need to break this file into the following format :-
File A
A BWCIF abc 02022004061853
Drec1 abc abc abc abc abc cdef A
Drec3 abc abc abc abc abc cdef A
Drec5 abc abc abc abc abc cdef A
Drec7 abc abc abc abc abc cdef A
Drec9 abc abc abc abc abc cdef A
Drec11 abc abc abc abc abc cdef A
T 00006
File B
A BWCIF abc 02022004061853
Drec2 abc abc abc abc abc cdef I
Drec4 abc abc abc abc abc cdef I
Drec6 abc abc abc abc abc cdef I
Drec8 abc abc abc abc abc cdef I
Drec10 abc abc abc abc abc cdef I
T 00005
I have the following syntax to help split the file :-
cat abc| awk 'substr($1,1,1)~/A/ {print $0}' > A_file
cat abc| awk 'substr($NF,length($NF),1)~/A/ {print $0}' >> A_file
cat abc| awk 'substr($1,1,1)~/T/ {print $0}' >> A_file
cat abc| awk 'substr($1,1,1)~/A/ {print $0}' > I_file
cat abc| awk 'substr($NF,length($NF),1)~/I/ {print $0}' >> I_file
cat abc| awk 'substr($1,1,1)~/T/ {print $0}' >> I_file
The problem i have now is that i don't know how to re-create the trailer record(T) based on the new record count.It should show 5 and 6 respectively for the I file and the A file respectively. The syntax above just shows the old record count which is 11. Can someone please help me with this.
Thanks in advance for all the help.