001、插入列
root@DESKTOP-1N42TVH:/home/test3# ls
a.txt b.txt
root@DESKTOP-1N42TVH:/home/test3# cat a.txt
e r s
s f w
z x v
z v e
root@DESKTOP-1N42TVH:/home/test3# cat b.txt ## 测试数据, 将a.txt的第3列插入b.txt的2列和3列之间
3 4 2 8
1 3 9 0
1 2 3 4
4 4 7 7
root@DESKTOP-1N42TVH:/home/test3# awk '{print $3}' a.txt | paste -d " " - b.txt ## 提取列并合并
s 3 4 2 8
w 1 3 9 0
v 1 2 3 4
e 4 4 7 7
root@DESKTOP-1N42TVH:/home/test3# awk '{print $3}' a.txt | paste -d " " - b.txt | awk '{$3 = $3" "$1; $1 = ""; print $0}'
3 4 s 2 8 ## 插入列
1 3 w 9 0
1 2 v 3 4
4 4 e 7 7
root@DESKTOP-1N42TVH:/home/test3# awk '{print $3}' a.txt | paste -d " " - b.txt | awk '{$3 = $3" "$1; $1 = ""; print $0}' | sed 's/^[\t ]\+//'
3 4 s 2 8 ## 删除开头的空格
1 3 w 9 0
1 2 v 3 4
4 4 e 7 7