Uday Vernekar wrote: > Dear All, > > Slight Correction Made in Above Code. > I am grepping this Pattern depending on run count which will Always same > Pass count and Fail count will Vary. > | 72| Traffic Test | 1| 561| > > [Code] > #!/usr/bin/perl > > use 5.10.0; > use strict; > use warnings; > > my $var=`grep -nr "| 72| Traffic Test | 1| 561|" > /tmp/EO-PCPE-23-10GT`; > print "$var"; > my $failed = (split /\|/, $var)[6]; > > print "failed=$failed\n"; > > $failed =~ s/^\s+//; > > print "failed=$failed\n"; > > > if ($failed) { > say 'Failed'; > } > else { > say 'Sucsess'; > } > > [code] > > > > > output: for Fail condition > > 43629: | 72| Traffic Test | 1| 561| 560| 1| > (none) > failed= 1 > failed=1 > Failed > > > output:for pass condition > > 43629: | 72| Traffic Test | 1| 561| 561| 0| > (none) > failed= 0 > failed=0 > Sucsess > > > Please suggest...... > > with Regards > Uday V G > Why shell out to the grep command when Perl is perfectly capable of doing the same?
Here's an example that uses split and tests the relevant fields. This could also be accomplished with a regex, but I think the split approach is cleaner. [code] #!/usr/bin/perl use 5.10.0; use strict; use warnings; # throw away the first 3 lines <DATA> for 1..3; while (my $line = <DATA>) { my ($test, $run, $failed) = (split /\|/, $line)[1,4,6]; next unless ($test == 72 and $run == 561); print "Line $.:$line"; $failed =~ s/^\s+//; say "failed=$failed"; say $failed ? 'Failed' : 'Success'; } __DATA__ U/A/S|Test| Test |Loop | Run |Pass |Fail | Arguments | Name |Count|Count|Count|Count | -----+----+---------------------------+-----+-----+-----+-----+--------------+--------------- | 72| Traffic Test | 1| 11| 11| 0| (none) | 72| Traffic Test | 1| 561| 11| 1| (none) [/code] If you need to process multiple files in a directory tree as the -r option in your grep command implies, then make use of the File::Find module. http://search.cpan.org/~rjbs/perl-5.20.0/ext/File-Find/lib/File/Find.pm -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/