Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a new column to the file

Tags:

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
like image 580
user951487 Avatar asked Sep 26 '11 07:09

user951487


People also ask

How do I add a column to a Unix file?

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.

How do you add a column value in awk?

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.


1 Answers

awk '{print $0, "F11"}' original.file

like image 103
nick Avatar answered Oct 23 '22 20:10

nick