Is there a way to completely delete fields in awk, so that extra delimiters do not print?

后端 未结 9 1070
醉话见心
醉话见心 2020-12-20 12:52

Consider the following command:

$ gawk -F"\\t" "BEGIN{OFS=\\"\\t\\"}{$2=$3=\\"\\"; p         


        
9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 13:19

    You can't delete fields in the middle, but you can delete fields at the end, by decrementing NF.

    So you can shift all the later fields down to overwrite $2 and $3 then decrement NF by two, which erases the last two fields:

    $ echo 1 2 3 4 5 6 7 | awk '{for(i=2; i

提交回复
热议问题