Juergen
Juergen

Reputation: 351

awk last argument before NF?

I tried to print the argument before $NF. However $NF-- doesn't do the trick. What is the solution to this? Problem is, I dono how many args I get, so I always need $NF and the arg before.

Kind Regards

Juergen

host -t ptr 1.1.1.1 | awk '/pointer/ {num=split($0,a, "."); print a[num-2] "." a[num-1] ;}'

foo.tld

Upvotes: 15

Views: 17574

Answers (1)

Eduardo Ivanec
Eduardo Ivanec

Reputation: 11862

You can use $(NF - 1) to get the next to last field. So in your case:

awk '{print $(NF - 1), $NF}'

Upvotes: 26

Related Questions