文件1
A P
B Q
A Q
C R
C P
D S
E T
文件2
A X1
C X2
Q X3
R X4
T X5
输出文件
A X1 P
B Q X3
A X1 Q X3
C X2 R X4
C X2 P
D S
E T X5
答案1
$ cat file1
A P
B Q
A Q
C R
C P
D S
E T
$ cat file2
A X1
C X2
Q X3
R X4
T X5
$ awk -v OFS='\t' 'FNR==NR{a[$1]=$2;next} {print $1, a[$1], $2, a[$2]}' file2 file1
A X1 P
B Q X3
A X1 Q X3
C X2 R X4
C X2 P
D S
E T X5
$