【发布时间】:2020-10-29 05:28:39
【问题描述】:
我正在尝试将 file1 的第一列与 file2 的第一列进行比较。如果有匹配-> 打印 file2 的 column2 中的对应值
检查了一些建议,但没有找到正确的代码。
file1 (single column)
987
675
21
23
21
2645
file2 (two columns)
234 def
987 one
22 abc
21 two
675 three
24 rty
25 qwe
预期输出:
one
three
two
two
我正在使用:
awk 'FNR==NR { r[$1] = $0; next; } r[$1] { print r[$1]; next }' file2 file1
我明白了:
987 one
675 three
21 two
21 two
有什么建议吗? 谢谢!
【问题讨论】: