linux 实现两个文件指定列的替换

1、

root@PC1:/home/test2# ls
test1.txt  test2.txt
root@PC1:/home/test2# cat test1.txt
01 02 03 04
05 06 07 08
09 10 11 12
13 14 15 16
17 18 19 20
root@PC1:/home/test2# cat test2.txt
17 18 19 20
13 14 15 16
09 10 11 12
05 06 07 08
01 02 03 04
root@PC1:/home/test2# awk 'FNR==NR{a[NR]=$2;next}{$4=a[FNR]}{print}' test1.txt test2.txt   ## 使用test1.txt的第2列替换test2.txt的第4列,原理不清楚
17 18 19 02
13 14 15 06
09 10 11 10
05 06 07 14
01 02 03 18

 

posted @ 2021-12-27 10:22  小鲨鱼2018  阅读(390)  评论(0编辑  收藏  举报