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




On Tue, Jun 24, 2014 at 5:31 PM, Uday Vernekar <vernekaru...@gmail.com>
wrote:

> Dear All,
>
> Please correct Me If i am wrong:Here's the code which I wrote
>
> [code]
> #!/usr/bin/perl
>
> use 5.10.0;
> use strict;
> use warnings;
>
> my $var=`grep -nr "|  72| Traffic Test              |    1|  561|  561|
> 1| (none)"  /tmp/EO-PCPE-23-10GT`;
>
>
> # extract the "failed" field i.e., 6th field
> my $failed = (split /\|/, $var)[6];
>
>
> # strip leading spaces
> $failed =~ s/^\s+//;
> printf "$failed";
>
>
>
> if ($failed) {
>     say 'Failed';
>     }
>     else {
>         say 'Sucsess';
>         }
>
> [code]
>
> Regards Uday V G
>
>
>
> On Tue, Jun 24, 2014 at 4:25 PM, Charles DeRykus <dery...@gmail.com>
> wrote:
>
>> On Tue, Jun 24, 2014 at 3:15 AM, Uday Vernekar <vernekaru...@gmail.com>
>> wrote:
>> > Hi all,
>> >
>> > I tried this its working fine when we have this pattern at hand,but the
>> > pattern is in a log file which is very large and i need to grep this
>> pattern
>> > first from the generated log file then Match.how do i do it?
>> >
>>
>> Once $pattern grepped out from log, then:
>>
>> $fail_count = ( (split(/\Q$pattern/, $_) )[-2];
>>
>> or maybe:
>>
>>     my $re = qr/\Q$pattern/;
>>     $fail_count = ( split( /$re/, $_) )[-2];
>>
>>        For explanation of "qr", see: Regexp Quote-Like Operators in
>> perlop.
>>
>> > On Tue, Jun 24, 2014 at 1:30 PM, Uday Vernekar <vernekaru...@gmail.com>
>> > wrote:
>> >>
>> >> Thanks everybody will work out the Feasible option from all
>> >> these......Thanks a lot
>> >>
>> >>
>> >>
>> >> On Mon, Jun 23, 2014 at 10:12 PM, Charles DeRykus <dery...@gmail.com>
>> >> wrote:
>> >>>
>> >>> On Mon, Jun 23, 2014 at 2:42 AM, Uday Vernekar <
>> vernekaru...@gmail.com>
>> >>> wrote:
>> >>> > Hi All,
>> >>> >
>> >>> >
>> >>> > I have following Pattern from which I need to grep only the Fail
>> count
>> >>> > and
>> >>> > store that in a variable.
>> >>> >
>> >>> > U/A/S|Test|            Test           |Loop  | Run |Pass |Fail    |
>> >>> > Arguments
>> >>> >          |                  Name         |Count|Count|Count|Count |
>> >>> >
>> >>> >
>> -----+----+---------------------------+-----+-----+-----+-----+--------------+---------------
>> >>> >          |  72| Traffic Test             |      1|      11|     11|
>> >>> > 0|
>> >>> > (none)
>> >>> >
>> >>> > based on fail count value need to print
>> >>> >
>> >>> > if 0------Sucess
>> >>> > if >0------Fail
>> >>> >
>> >>>
>> >>> Another way:
>> >>>
>> >>>    while ( <DATA>) {
>> >>>         ...
>> >>>         my $fail_count - ( split( /\|/, $_  ) )[-2];
>> >>>        ...
>> >>>    }
>> >>>
>> >>> See: perldoc -f split
>> >>>
>> >>> --
>> >>> Charles DeRykus
>> >>>
>> >>> --
>> >>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> >>> For additional commands, e-mail: beginners-h...@perl.org
>> >>> http://learn.perl.org/
>> >>>
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> *********************************************************
>> >> Don't ask them WHY they hurt you,
>> >> because all they'll tell you is lies and excuses.
>> >>  Just know they were wrong, and try to move on.
>> >> **********************************************************
>> >
>> >
>> >
>> >
>> > --
>> > *********************************************************
>> > Don't ask them WHY they hurt you,
>> > because all they'll tell you is lies and excuses.
>> >  Just know they were wrong, and try to move on.
>> > **********************************************************
>>
>
>
>
> --
> *********************************************************
> Don't ask them WHY they hurt you,
> because all they'll tell you is lies and excuses.
>  Just know they were wrong, and try to move on.
> **********************************************************
>



-- 
*********************************************************
Don't ask them WHY they hurt you,
because all they'll tell you is lies and excuses.
 Just know they were wrong, and try to move on.
**********************************************************

Reply via email to