|
|
Question : Split Text File-Perl/Unix Script
|
|
I am a complete nowise and would greatly appreciate help with a script.
I have a file which needs to be split into multiple file based on the error code. Each record begins with
REPORT: RESP FRONT SYSTEM and end with END OF REPORT between these line is some errorcd. If the program is provided with the following text in the parameter file it should create 2 different files for every errorcd not creating a file for the once which don't have any error.
REPORT: RESP FRONT SYSTEM RUN DATE: 20080529 REPORT
RECORD SEQ ERROR TYPE NO CODE ERROR DESCRIPTION BHD 0018586 132 NOT AUTHORIZED. BHD 0019529 132 NOT AUTHORIZED. BHD 0019529 235 NOT VALID. (This line should not appear on the new file since the seq_no for the previous is same) END OF REPORT SUBMITTER ID: DEVON FILE ID: 407 REJECTED PROD RECORD SEQ ERROR TYPE NO CODE ERROR DESCRIPTION END OF REPORT
Thanks for the help in advance
|
Answer : Split Text File-Perl/Unix Script
|
|
$/="END OF REPORT\n"; $n=1; while( <> ){ next unless /TYPE\s+NO\s+CODE\s+ERROR\s+DESCRIPTION.*\d/s; open STDOUT,">$ARGV.$n" or die "$ARGV.$n $!"; $n++; s/^(\s*\w+\s+(\d+)\s.*\n)(\s*\w+\s+\2\s.*\n)+/$1/mg; s/.*?(REPORT: RESP\s+FRONT SYSTEM)/$1/s; print; }
|
|
|
|