2013-01-24 91 views
0

想要在perl中的backtik运算符内运行awk命令。这给了我一个错误。我试图逃避报价,管道,但似乎没有工作。在perl脚本中运行awk命令

my @fieldCnt=`head -1 $inputFileDir/$cmdParams{mas}|awk -F, \'print NF\'`; 
+4

你为什么在Perl内运行awk? – TLP

+0

awk命令中的花括号({}}在哪里? – Vijay

+0

非常感谢您的信息。缺少大括号是问题 – Arav

回答

4

我只想做perl脚本中,而随后用awk。如果我理解你想达到什么样的,你正在寻找项目的用逗号分隔的行数,然后

# Open the file for reading 
open my $fh,"$cmdParams{mas}" or die "Unable to open: $cmdParams{mas}"; 
my $firstLine = <$fh>; # Get the first line 
close($fh); # close the file 
my @items = split(',',$firstLine); # Get the items separated by comma's 
$numberOfFields = scalar(@items); # Get the count of the number of items 

希望这是有帮助的。

+0

非常感谢。我不想打开这些文件。我想用awk尝试一行代码。 AWK大括号缺失,这是正确的答案 – Arav

+0

非常欢迎。 – Glenn