in reply to Re^5: How to fetch the value of unix command result
in thread How to fetch the value of unix command result

how can i assign 4 to $c1 and 7 to $c1

Are you sure you mean that, or should one of those $c1s be $c ?

poj

Replies are listed 'Best First'.
Re^7: How to fetch the value of unix command result
by rajsai28 (Novice) on Jun 30, 2013 at 14:14 UTC
    Hi Expert,

    I mean 4 should be assigned to $c and 7 should be assigned to $c1

    Thanks

      $c = $count{'KCEHC'}; #4 $c1 = $count{'CHECK'}; #7
      poj
        Hi Expert,

        I am executing unix command 'gunzip -c test.txt.gz |cut -f3 -d'|'|sort|uniq -c' and stroing the value in a variable, the zip file contains records as shown below:

        ABC|123|CHECK|1| DEF|456|CHECK|1| GHI|789|CHECK|1| ABC|123|CHECK|1| DEF|456|CHECK|1| GHI|789|CHECK|1| ABC|123|CHECK|1| DEF|456|KCEHC|1| GHI|789|KCEHC|1| JKL|101|KCEHC|2|

        I have used the code as shown below, i am executing the unix commands and storing the value in a variable and from the results i am fetching only numeric value

        #!/usr/bin/env perl use warnings; use strict; use IO::Zlib; my $fh = IO::Zlib->new('test.txt.gz', 'rb') or die "Zlib failed: $!"; my %count; $count{$_}++ for map { (split /\|/)[2] } <$fh>; foreach $key(%count){ $c = $count{$key}; $c1 = $count{$key}; }

        gives me this output:

        $c = 4 $c1 = 4

        The output of dumper

        $VAR1 = 'CHECK'; $VAR2 = 7; $VAR3 = 'KCHEC'; $VAR4 = 4;

        I also tired to grep the CHECK - $r = grep /CHECK/, $r, it returns a 1

        i want store the value as CHECK= 7 and KCHEC = 4, separately

        Experts any help on this, thanks,regards