AWK:如何抑制默认打印

标签 awk

AWK:如何禁止默认打印 以下 awk if 语句总是打印 $0。如何阻止它这样做

    ( nodeComplete && count ) 
    {

        #print $0
        #print count;

        for (i = 0; i < count; i++) {print array1[i];};

        nodeComplete=0;
        count=0;
    }

最佳答案

欢迎使用 SO,尝试更改大括号 { 的位置,如果有帮助请告诉我。

( nodeComplete && count ){
  #print $0
  #print count;
  for (i = 0; i < count; i++) {print array1[i];};
  nodeComplete=0;
  count=0;
}

上述变化的解释:

logic behind this is simple { next to condition means coming statements should be executed as per condition. If you put them in next line then it will all together a different set of block and condition will be a different block. So if condition is TRUE then it will print complete line since { is altogether a separate block.

关于AWK:如何抑制默认打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52090128/

相关文章:

awk - 为什么我的 awk 代码应该只在特定条件下打印单词,但实际上却打印所有行?

bash - 使用 Perl、sed、awk 替换多行模式

linux - 是否可以将 awk 中的打印语句通过管道传输到多个文本文件?

bash - 使用 awk 将大型复杂的一列文件拆分为多列

linux - 尝试理解简单的 Linux 代码

awk - 根据单列(AWK)中的值拆分大文件

AWK:基于现有列派生字段(创建新列)

awk - 使用 awk 输出的每一行作为 grep 模式

linux - 如何在awk中将文件的列名作为变量传递

linux - 删除一段代码