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

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

Consider the following command:

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


        
9条回答
  •  清歌不尽
    2020-12-20 13:28

    This is an oldie but goodie.

    As Jonathan points out, you can't delete fields in the middle, but you can replace their contents with the contents of other fields. And you can make a reusable function to handle the deletion for you.

    $ cat test.awk
    function rmcol(col,     i) {
      for (i=col; i

提交回复
热议问题