将 2 个文件合并到第三个文件中,使用列作为索引并合并行
我一直在学习 awk,遇到一个我无法解决的问题,如果可以的话请帮忙。
我有 2 个使用 awk、sort 和 uniq -c 生成的文件。
文件 1 的格式为:
1 aaa.c 10/10/2010
1 bbb.h 1/1/2011
3 ccc.c 2/2/2012
1 ccc.c 20/6/2011
1 ddd.c 1/1/2010
1 ddd.c 2/4/1999
1 ddd.c 7/1/2012
1 ddd.c 10/1/1977
含义: number_of_equal_files name date(因此,来自同一日期的 3 个文件 ccc.c 和来自另一个日期的 1 个文件 ccc.c)
文件 2 的格式为:
4 ddd.c
2 ccc.c
3 xxx.c
含义: number_of_ different_dates 名称(因此,ccc.c 已被发现具有 2 个不同的日期)->我使用反向 grep 删除了 number=1 的文件,所以不会有任何
我想要做的是生成格式为
number_of_ different_dates name date1 date2 date 3 date4 (...) 的
第三个文件喜欢:
2 ccc.c 2/2/2012 20/6/2011
4 ddd.c 1/1/2010 2/4/1999 7/1/2012 10/1/1977
提前致谢!
I've been studying awk and i've come upon a problem i'm not being able to solve, please help if you can.
I have 2 files I generated using awk, sort and uniq -c.
File 1 is in the format:
1 aaa.c 10/10/2010
1 bbb.h 1/1/2011
3 ccc.c 2/2/2012
1 ccc.c 20/6/2011
1 ddd.c 1/1/2010
1 ddd.c 2/4/1999
1 ddd.c 7/1/2012
1 ddd.c 10/1/1977
Meaning: number_of_equal_files name date (so, 3 files ccc.c from the same date and 1 file ccc.c from another)
File 2 is in the format:
4 ddd.c
2 ccc.c
3 xxx.c
Meaning: number_of_different_dates name (so, ccc.c has been found with 2 different dates) -> files that would have number=1 i removed usind a reverse grep, so there won't be any
What i'd like to do is to generate a third file in the format
number_of_different_dates name date1 date2 date 3 date4 (...)
something like:
2 ccc.c 2/2/2012 20/6/2011
4 ddd.c 1/1/2010 2/4/1999 7/1/2012 10/1/1977
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够仅使用第一个文件作为输入来获得该结果。下面使用两个关联数组。第一个收集文件被查看的次数,第二个收集日期。
END
块仅打印出现多次的条目。You should be able to get that result using only the first file as input. The following uses two associative arrays. The first collects the number of times a file is seen and the second collects the dates. The
END
block just prints the entries that appeared more than once.你可以尝试这样的事情 -
测试:
You can try something like this -
Test: