Alkass |
07-30-2011 08:57 AM |
Executing a awk command inside perl script --
Hello experts
I want to execute a awk command, which reads from txt files and sums the numbers from the first column for those listed only inside a <init> block -- The awk command is like
Code:
awk '/<\/?init>/{x = !x}x{a++}x && a > 2{sum+=$1}END{printf"%E" "\n", sum}
So, I want to execute it inside a perl script, and execute the awk command for the infile which is also defined outside awk loop, ie doing something like
Code:
foreach $infile (@ARGV) {
$gzin = gzopen($infile, "r") || die ("Couldn't open file $infile\n");
# No. events and cross-section from current file
my $xsec= `awk '/<\/?init>/{x = !x}x{a++}x && a > 2{sum+=$1}END{printf"%E" "\n", sum}' $infile`;
But this does not work and I get this
Code:
Use of uninitialized value in concatenation (.) or string at merge.pl line 54.
awk: /</?init>/{x = !x}x{a++}x && a > 2{sum+=}END{printf"%E" "
awk: ^ unterminated regexp
awk: cmd. line:1: /</?init>/{x = !x}x{a++}x && a > 2{sum+=}END{printf"%E" "
awk: cmd. line:1: ^ unexpected newline or end of string
awk: cmd. line:1: ", sum}
awk: cmd. line:1: ^ unterminated string
Argument "" isn't numeric in numeric eq (==) at merge.pl line 98.
Any ideas ?
|