What is $(NF) means?

HI

what does the $(NF) means.
here i want to understand the working.
what i know is that in awk NF argument will tell number of column in a file

i have below file

alpha
a
beta
b

if i use command

cat kv | paste - - | awk '{print $1," "$2 "------>"$(NF)}' 

i get the o/p as

alpha  a------>a
beta  b------>b

from above o/p i can understand that is printing last word of the each line. but not able to understand it why
as NF argument tells number of argument.
net able to understand its working logic.

It's the same as $NF - the last field in the input line regardless of its actual field number.
awk splits the line into n fields and then assigns n to NF (number of fields?) If you have three fields, $NF = $3 = the value of the last field in line. Same for 20 or hundreds of fields in a line. You can go a step beyond - what do you think $(NF-1) evaluates to? Here, the parentheses are necessary!

1 Like

thx Rudic for the explanation.

$(NF-1) 

this will print alpha and beta.
thx for explaining in easy way .

Yes, in your above example it will print alpha and beta, but in general, it will print the before-last field.