【发布时间】:2015-02-11 08:01:30
【问题描述】:
我在 awk 中有一个不寻常的合并请求。希望你能帮忙。
文件1
pl1,prop1,20
pl1,prop2,30
pl1,prop3,40
pl2,prop1,70
pl2,prop2,80
pl2,prop3,90
pl3,prop1,120
pl3,prop2,130
pl3,prop3,140
文件2
store1,pl1
store2,pl1
store3,pl2
store4,pl3
store5,pl2
store6,pl1
输出:
prop1, store1-20, store2-20, store3-70, store4-120, store5-70, store6-20
prop2, store1-30, store2-30, store3-80, store4-130, store5-80, store6-30
prop3, store1-40, store2-40, store3-90, store4-140, store5-90, store6-40
规则
- file1.column1 应该匹配 file2.column2
- 对于所有匹配的行 - file2.column1 应与 file1.currentLine.column3 连接
非常感谢,
【问题讨论】:
-
How to merge two files using AWK? 的可能重复项(用例略有不同,但处理第二列而不是第一列并更改输出顺序听起来并不难,试一试,然后询问是否你被困在尝试:))
-
感谢 Tensibai,会尽力让您知道
-
我的问题和How to merge two files using AWK?很不一样。输出由 file1.column2 驱动,此值不应重复。除此之外,我仍然在使用 Awk,因此很难利用所有选项。