按列消除部分重复的行并保留最后一行
我有一个如下所示的文件:
2011-03-21 name001 line1
2011-03-21 name002 line2
2011-03-21 name003 line3
2011-03-22 name002 line4
2011-03-22 name001 line5
对于每个名称,我只想要它的最后一次出现。所以,我期望结果是:
2011-03-21 name003 line3
2011-03-22 name002 line4
2011-03-22 name001 line5
有人能给我一个 bash/awk/sed 的解决方案吗?
I have a file that looks like this:
2011-03-21 name001 line1
2011-03-21 name002 line2
2011-03-21 name003 line3
2011-03-22 name002 line4
2011-03-22 name001 line5
for each name, I only want its last appearance. So, I expect the result to be:
2011-03-21 name003 line3
2011-03-22 name002 line4
2011-03-22 name001 line5
Could someone give me a solution with bash/awk/sed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
此代码按第二个字段但从文件或文本末尾获取 uniq 行(如结果示例中所示)
This code get uniq lines by second field but from the end of file or text (like in your result example)
如果出现顺序很重要:
基于首次出现:
基于最后一次出现:
If order of appearance is important:
Based on first appearance:
Based on last appearance:
栏现在没有重复的行
bar now has no duplicated lines
编辑:这是一个真正回答问题的版本。
EDIT: Here's a version that actually answers the question.