Replace last field on last line with awk
3 answers
the END section is executed AFTER the last line has been processed, so you assign a $2
value after printing the last line.
There is also no guarantee that $ 2 or $ 0 or any of the fields will be stored in the END section (POSIX does not specify it), but IF in your awk, $ 2, etc. Is saved, then you need something like:
awk '
NR>1{print prev}
{prev=$0}
END {$2=-9; print}
'
If it doesn't, you need to create $ 0 first:
awk '
NR>1{print prev}
{prev=$0}
END {$0=prev; $2=-9; print}
'
+3
source to share