I would like to overwrite the last field (2 fields in total) of the last line of a file with the value -9. I am using this command:
awk 'END{$2=-9}1' file.txt > new_file.txt
but it doesn't seem to work (no replacement is done). Why's that? Any ideas?
Thanks!
You'll need to print the previous line, and then you can manipulate the last line in the END block before it has already been printed:
awk 'NR > 1 {print prev} {prev = $0} END {$2=-9; print}'
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