Alex Rivera | Logout

How to print last two columns using awk

Asked 2010-11-29T14:59:22.610
126

All I want is the last two columns printed.

awk
Edit
Report

1 Answer

7

@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
answered 2013-03-18T09:45:26.177

Your Answer