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
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
awk '{print $0, "F11"}' original.file
try:
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
If you want to add a column to a file, you can do the following.
remark: We assume that the field separator
FS
equals to the string"fs"
. You can replace this by anything, or if you just use <blanks> as field separator, you can remove theBEGIN{FS=OFS="fs"}
part in any of the following solutions.add a column at the beginning:
add a column at the end:
add a column before column
n
:add column after column
n
:add a column before each of column
n1
<n2
< ... <nm
: (start at the back)or for different values
add a column after each of column
n1
<n2
< ... <nm
: (start at the back)or for different values