awk的功能特別強大,其中一個功能就是生成新的列,不論這列是在第一列,最后一列,還是中間,隨你任性插入。
舉例來說,有下列文件test1.txt
test1.txt
a b c
1 2 3
現在我想在test1.txt
的末尾新添一列,變成test2.txt
test2.txt
a b c cwy
1 2 3 cwy
則可以用到命令awk '{print $0,"cwy"}' test1.txt > test2.txt
如果是在test1.txt
的中間新添一列,變成test3.txt
test3.txt
a b cwy c
1 2 cwy 3
則可以用到命令awk '{print $1,$2,"cwy",$3}' test1.txt > test3.txt
其他的以此類推。