How to print last two columns using awk

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

All I want is the last two columns printed.

6条回答
  •  生来不讨喜
    2021-01-29 19:38

    using gawk exhibits the problem:

     gawk '{ print $NF-1, $NF}' filename
    1 2
    2 3
    -1 one
    -1 three
    # cat filename
    1 2
    2 3
    one
    one two three
    

    I just put gawk on Solaris 10 M4000: So, gawk is the cuplrit on the $NF-1 vs. $(NF-1) issue. Next question what does POSIX say? per:

    http://www.opengroup.org/onlinepubs/009695399/utilities/awk.html
    

    There is no direction one way or the other. Not good. gawk implies subtraction, other awks imply field number or subtraction. hmm.

提交回复
热议问题