AWK:将两个文件中的字段与多个字段进行比较

AWK:将两个文件中的字段与多个字段进行比较,awk,Awk,有人能帮我吗 文件1: 文件2: 输出: 以下awk将帮助您开始: awk 'BEGIN { FS = "|" } NR == FNR { # while reading the 1st file # store its records in the array f f[$3] = $0 next } $1 in f { # when match is found # print all values print f[$1], $0> }' file1 file2 Re

有人能帮我吗

文件1:

文件2:

输出:

以下awk将帮助您开始:

awk 'BEGIN {
  FS = "|"
 }
NR == FNR {
# while reading the 1st file
# store its records in the array f
f[$3] = $0
  next
 }
$1 in f {
# when match is found
# print all values
print f[$1], $0>   }' file1 file2


Red|Circle|123|apple|orange|grapes 123|Square|banana|blueberry

Red|Circle|123|apple|orange|grapes 123|Triangle|strawberry|grapes

那么你的问题是什么?我不知道你是如何得出这个结果的。你为什么让我们猜?对不起。我需要组合文件1的字段3和文件2的字段1匹配的2个文件。谢谢
123|Square|banana|blueberry

123|Triangle|strawberry|grapes

347|Circle|orange|strawberry
Red|Circle|123|apple|orange|grapes|Square|banana|blueberry

Red|Circle|123|apple|orange|grapes|Triangle|strawberry|grapes
awk 'BEGIN {
  FS = "|"
 }
NR == FNR {
# while reading the 1st file
# store its records in the array f
f[$3] = $0
  next
 }
$1 in f {
# when match is found
# print all values
print f[$1], $0>   }' file1 file2


Red|Circle|123|apple|orange|grapes 123|Square|banana|blueberry

Red|Circle|123|apple|orange|grapes 123|Triangle|strawberry|grapes