【问题标题】:running awk command in perl script在 perl 脚本中运行 awk 命令
【发布时间】:2013-01-24 12:46:15
【问题描述】:

想在 perl 的 backtik 运算符中运行 awk 命令。它给了我一个错误。我尝试转义引号,管道但似乎没有任何效果。

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

【问题讨论】:

  • 你为什么在 perl 中运行 awk?
  • 你的 awk 命令中的花括号({})在哪里?
  • 非常感谢您提供的信息。缺少大括号是问题

标签: perl


【解决方案1】:

我只会在 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

希望这会有所帮助。

【讨论】:

  • 非常感谢。我不想打开文件。我想尝试使用 awk 的一行代码。缺少正确答案的 AWK 大括号
猜你喜欢
  • 2018-08-28
  • 2014-02-15
  • 2016-11-22
  • 1970-01-01
  • 2013-07-18
  • 1970-01-01
  • 1970-01-01
  • 2011-05-31
  • 1970-01-01
相关资源
最近更新 更多