Hi
I am writing a perl script which checks for the specific column values from a file and writes to the OUT file.
So the feed file has a header information and footer information.
I header information isaround107 lines i.e.
Starts with
START-OF-FILE
.......
so on ....
TIMESTARTED=Thu Aug 25 01:03:50 BST 2011
START-OF-DATA
# PRODUCT=Corp/Pfd
After the last line "# PRODUCT=Corp/Pfd" the actual data would start.
The footer information is 4 lines i.e.
END-OF-DATA
DATARECORDS=1275983
TIMEFINISHED=Thu Aug 25 02:27:02 BST 2011
END-OF-FILE
Now, My perl script is as below:
#!/usr/bin/perl
$file='file';
open(FILE,$file)|| die ("could not open file $file: $!"); # note minor changes in this line, too
open(OUT1,'>','badfile');
open(OUT2,'>','goodfile');
my @fields;
$line = $_;
while (<FILE>) {
$line = $_;
@fields = split (/\|/, $line);
<<<<<< 1) Here Before going to check the column values, I need to write the HEADER and FOOTER information to the Goodfile. >>>>>>>>>
if( $fields[32] eq "N.A." && $fields[33] eq "N.A." && $fields[34] eq "N.A." && $fields[38] eq "N.A." && ($fields[62] eq "N.A." || $fields[62] eq " "))
{
print OUT1 $line; -----> Badfile
}
else
{
print OUT2 $line; ----> Goodfile
}
}
close FILE;
close OUT1;
close OUT2;
1)Here Before going to check the column values, I need to write the HEADER and FOOTER information to the Goodfile
2) Also, I need to calculate the Number of Records in the Good file and then change the FOOTER Information as:
END-OF-DATA
DATARECORDS=1275983 --> New Rowcount from the Goodfile
TIMEFINISHED=Thu Aug 25 02:27:02 BST 2011
END-OF-FILE
Could anyone please help me out in solving this. Help would be really appreciated.