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
$NF as with any $fieldnumber usage in awk prints the value of the data element stored in the last field on every line. So if the first line in a file has 4 fields and the second line has 3, NF for each line is 4 and 3 respectively, and $NF is the respective values in $4 on the first line and $3 on the second line.
If you make awk to spit out its output you can pipe it to the next processor. If you use getline, and in particular within a loop, you might not see the end. getline should be used only for a line and an eventual dependency on the next line.
NF is a predefined variable whose value is the number of fields in the current record. awk automatically updates the value of NF each time it reads a record. No matter how many fields there are, the last field in a record can be represented by $NF .
You can use $(NF - 1)
to get the next to last field. So in your case:
awk '{print $(NF - 1), $NF}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With