001、 正确做法
[root@pc1 test01]# ls a.txt b.txt [root@pc1 test01]# cat a.txt A:10 B:5 C:12 [root@pc1 test01]# cat b.txt 100 A 50 B 42 C [root@pc1 test01]# awk '{if(NR == FNR) {print $2} else {print $1}}' FS=":" a.txt FS=" " b.txt 10 5 12 100 50 42
002、错误做法
[root@pc1 test01]# ls a.txt b.txt [root@pc1 test01]# cat a.txt A:10 B:5 C:12 [root@pc1 test01]# cat b.txt 100 A 50 B 42 C [root@pc1 test01]# awk '{if(NR == FNR) {FS = ":"; print $2} else {FS = " "; print $1}}' a.txt b.txt 5 12 100 A 50 42
。