Extract Lines when Column K is empty with AWK/Perl

后端 未结 3 1910
一生所求
一生所求 2021-02-19 04:23

I have data that looks like this:

foo 78 xxx
bar    yyy
qux 99 zzz
xuq    xyz

They are tab delimited. How can I extract lines where column 2 is

3条回答
  •  没有蜡笔的小新
    2021-02-19 04:57

    You need to specifically set the field separator to a TAB character:

    > cat qq.in
      foo     78      xxx
      bar             yyy
      qux     99      zzz
      xuq             xyz
    > cat qq.in | awk 'BEGIN {FS="\t"} $2=="" {print}'
      bar             yyy
      xuq             xyz
    

    The default behaviour for awk is to treat an FS of SPACE (the default) as a special case. From the man page:

    In the special case that FS is a single space, fields are separated by runs of spaces and/or tabs and/or newlines. (my italics)

提交回复
热议问题