Hi Friends,
As my old friends knows, I'm old to shell script but very new to perl script, currently I'm writing
a PERL script with the following functionality:
I've multiple product directories, like BUSS, FIN, SALES, MKT etc., :
/export/home/GLK/BUSS,
/export/home/GLK/FIN,
/export/home/GLK/SALES,
/export/home/GLK/MKT
etc..,
Above all directories will have one report file with the same name 'missing_party.rpt'.
This report file contains a lot of information, out of which I need to extract
only the lines which has the pattern "My dear boss(.....some info...) Thanks".
I've to redirect only the above pattern line into a output file "/export/home/OUTPUT/output.txt"
by discarding the remaining line.
I've written the below script, with the help of google
#!/usr/bin/perl
use File::Find;
use strict;
my $directory = "/export/home/GLK";
my $out_filename = "/export/home/GLK/output.txt";
find (\&process, $directory);
sub process
{
my @outLines; #Data we are going to output
my $line; #Data we are reading line by line
# Only parse files that end in .html
if ( $File::Find::name =~ /\missing_party.rpt$/ ) {
open (FILE, $File::Find::name ) or die "Cannot open file: $!";
open( OUTFILE, "> " . $out_filename ) or die "Cannot open file: $!";
# print "\n" . $File::Find::name . "\n";
while ( $line = <FILE> ) {
$line =~ m/"My dear boss(.....some info...) Thanks"/ ;
push(@outLines, $line);
print ( OUTFILE @outLines );
}
close FILE;
close ( OUTFILE );
undef ( @outLines );
}
}
The problem with the above script is, I need to extract only the information "My dear boss(.....some info...) Thanks" from the entire line. But current code is extracting complete line.
I dont know how to implement it.....
Could any one help me ... also is it possible to fine tune the above code...? Even though I'm new, requirement is for the optimal code.
Thanks in advance... / Mysore Ganapati.