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

Add another line at the end
print "c=$c c1=$c1\n";
and see what you get.
poj

Replies are listed 'Best First'.
Re^11: How to fetch the value of unix command result
by rajsai28 (Novice) on Jul 01, 2013 at 07:27 UTC
    Hi Experts,

    I have changed the field number now, to fetch the fields 3 and 4 instead of only field 3, then combine the field 3 and field 4 and get the count

    when i execute below the command in unix prompt

    gunzip -c $file|cut -f3,4 -d'|' |sort|uniq -c

    i got the below output

    2 11 CHECK|KCEHC

    My input:

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

    I have tired as below, please check the below code

    $fh = IO::Zlib->new( "$file", 'rb' ) or die "Zlib failed: $!"; $count{$_}++ for map { ( split /\|/ )[3,4] } <$fh>; print Dumper(%count);

    when i executed the script, i got the output as

    $VAR1 = ''; $VAR2 = 1; $VAR3 = 'CHECK'; $VAR4 = 11; $VAR5 = 'KCEHC'; $VAR6 = 11; $VAR7 = '';

    I am expecting my output as below

    CHECK|KCEHC 11

    I want to combine the two keys CHECK and KCEHC and assign a value 11. becuase two keys has same value

      Use join to combine

      $count{$_}++ for map { join '|',( split /\|/ )[2,3] } <$fh>;
      poj