Print second last column/field in awk

后端 未结 9 1934
野趣味
野趣味 2020-11-29 16:58

I want to print the second last column or field in awk. The number of fields is variable. I know that I should be able to use $NF but not sure how it can be use

相关标签:
9条回答
  • 2020-11-29 17:53

    Did you tried to start from right to left by using the rev command ? In this case you just need to print the 2nd column:

    seq 12 | xargs -n5 | rev | awk '{ print $2}' | rev
    4
    9
    11
    
    0 讨论(0)
  • 2020-11-29 17:55
    awk '{print $(NF-1)}'
    

    Should work

    0 讨论(0)
  • 2020-11-29 17:55
    awk ' { print ( $(NF-1) ) }' file
    
    0 讨论(0)
提交回复
热议问题