I'm not sure I understand the NF variable in awk.
My example file (test) contains one line:
1 2 3 4 5
The following works as expected:
awk '{print $1,$NF}' test
1 5
But the next example does not (i.e. the reverse):
awk '{print $NF,$1}' test
1
What am I missing here? I can print $NF by itself, or after $1, but not before.
Since it works fine for me, I am suspecting it could be carriage characters which could cause this issue, if this is the case then try following:
1- Check if carriage characters are present in any Input_file by doing:
cat -v Input_file
2- In case you find any carriage characters in your Input_file then you could remove them by doing following:
tr -d '\r' < Input_file > temp_file && mv temp_file Input_file
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