Search code examples
awkaddition

Add a new column to the file


How can I add a new column to a file using awk?

original.file

F1 F2 F3 ..F10 

add F11 to original.file

F1 F2 F3 ..F10 F11

Solution

  • try:

    awk 'BEGIN{getline to_add < "f3"}{print $0,to_add}' f
    

    Reads the column to add from file "f3" and saves it in the variable to_add. After that it adds the column to each line of file f.

    HTH Chris