How can I add a new column to a file with awk codes?
original.file
F1 F2 F3 ..F10
add F11 to original.file
F1 F2 F3 ..F10 F11
To insert a new column after the last column $NF indicates the value of last column. Hence,by assigning something to $(NF+1), a new field is inserted at the end automatically.
The -F',' tells awk that the field separator for the input is a comma. The {sum+=$4;} adds the value of the 4th column to a running total. The END{print sum;} tells awk to print the contents of sum after all lines are read.
awk '{print $0, "F11"}' original.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