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 used.
And this does not seem to work:
awk ' { print ( $NF-- ) } '
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 used.
And this does not seem to work:
awk ' { print ( $NF-- ) } '
If you have many columns and want to print all but not the three cloumns in the last, then this might help
awk '{ $NF="";$(NF-1)="";$(NF-2)="" ; print $0 }'
First decrements the value and then print it -
OR
You weren't far from the result! This does it:
This decrements the number of fields in one, so that
$NF
contains the former penultimate.Test
Let's generate some numbers and print them on groups of 5:
Let's print the penultimate on each line: