How to print last two columns using awk

后端 未结 6 1357
甜味超标
甜味超标 2021-01-29 19:16

All I want is the last two columns printed.

6条回答
  •  误落风尘
    2021-01-29 19:46

    @jim mcnamara: try using parentheses for around NF, i. e. $(NF-1) and $(NF) instead of $NF-1 and $NF (works on Mac OS X 10.6.8 for FreeBSD awkand gawk).

    echo '
    1 2
    2 3
    one
    one two three
    ' | gawk '{if (NF >= 2) print $(NF-1), $(NF);}'
    
    # output:
    # 1 2
    # 2 3
    # two three
    

提交回复
热议问题