in reply to Re: count total number of occurrence in all files
in thread Reaped: count total number of occurrence in all files
sorry friends, the problem is that my file consists of 4 lines but only the second line should match and give the total count. For example the following two files
data.txt @gi AGATC + E/AA# 1 @gi1 ACCTA + /66AE 3
The output should be:data1.txt @gi AGATC + //AA# 2 @gi1 ACCTA + #66AE 5
It should sum the second column of both file only if second line matches. but it is giving the output as:@gi AGATC + E/AA# 3 @gi1 ACCTA + /66AE 8
It is comparing all the four lines. My script is the same:@gi AGATC + E/AA# 1 @gi1 ACCTA + /66AE 3 @gi AGATC + //AA# 2 @gi1 ACCTA + #66AE 5
my %compare; $/=""; while (<>) { chomp; my ( $key, $value ) = split('\t\s', $_); push( @{ $compare{$key} }, $value ); } foreach my $key ( sort keys %compare ) { my $tot = 0; my $file_count = @ARGV; for my $val ( @{$compare{$key}} ) { $tot += ( split /:/, $val )[0]; } if ( @{ $compare{$key} } >= $file_count) { print join( "\t", $key, $tot, @{ $compare{$key} } ), "\n\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: count total number of occurrence in all files
by BillKSmith (Monsignor) on May 10, 2016 at 11:58 UTC |