我正在尝试在其中一个列上加入两个文件,输出应该是第二个文件的列和第一个文件中的一些列。
例如我的第一个文件是:
subscriberid unsubscribetime unsubscribeip listid statid unsubscribed
我的第二个文件是:
listid statid listname ownername owneremail createdatesubscribedidbouncetypebouncetimebouncerule
我需要将它们加入到“statid”列中,该列在第一个文件中排在第 5 位,在第二个文件中排在第 2 位。之后从第一个文件中添加第 2、第 3 和第 6 列。输出应该是:
listid statid listname ownername owneremail createdatesubscriberidbouncetypebouncetimebouncerule unsubscribetime unsubscribeip unsubscribed
我无法理解语法,但我使用的是这个命令:
awk 'NR==FNR{a[$5]=$2;next} $2 in a{print $0, a[$5]}' file1 file2
我认为它会给我 file2 列,因为“print $0”和第二列表单文件一设置为 a[$5]=$2,但它只输出 file2 列。
请问我哪里弄错了?如何将第 2、第 3 和第 6 列从 file1 连接到 file2?
非常感谢任何帮助/解释!
此示例中的两个文件只有一行