I have the following code that uses ‘paste’ and AWK script inside Perl.
use strict; use Data::Dumper; use Carp; use File::Basename; my @files = glob('result/*-*.txt'); my $tocheck = $ARGV[0] || 'M'; foreach my $file ( @files ) { my $base = basename($file,'.txt'); my @res = `paste <\(awk '\$4 == 'M' {sum += \$2 }END{print sum}' $file \) <\(awk '\$4 == 'M' {sum += \$3 }END{print sum}' $file\)`; chomp(@res); print '$base $res[0]\n'; }
Why it gives such error:
#sh: -c: line 1: syntax error near unexpected token `(' #sh: -c: line 1: `paste <(awk '$4 == 'M' {sum += $2 }END{print sum}' result/9547_1-S_aureus.txt ) <(awk '$4 == 'M' {sum += $3 }END{print sum}' #result/9547_1-S_aureus.txt)
What’s the correct way to do it?
Not entirely sure if this is a correct interpretation of your script, as there appears to be a lot of dead/unused code there, but there is certainly no need to go spawning paste or awk to do this: