对文本文件进行排序&删除重复项
我有一个很大的文本文件,每行都有 4 位代码和一些有关它们的信息。它看起来像这样:
3456 information
1234 info
2222 Some ohter info
我需要对此文件进行排序,因此代码在文件中按升序排列。另外,有些代码出现多次,所以我需要删除重复项。我可以使用 perl、awk 或其他脚本语言来完成此操作吗?
预先感谢,
-skazhy
I have a large text file with 4-digit codes and some information about them in every row. It looks something like this:
3456 information
1234 info
2222 Some ohter info
I need to sort this file, so the codes are in ascending order in the file. Also, some codes appear more than once, so I need to remove duplicates. Can I do this with perl, awk or some other scripting language?
Thanks in advance,
-skazhy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 IBM。
Google 的第一个结果:
unix 删除重复行
。From IBM.
1st result for Google:
unix remove duplicate lines
.您可以创建一个散列,然后逐行读取文件,对于
的哈希值,然后将(排序的)哈希值打印到文件中。
You can create a hash then read the file in line by line and for each line
Then print the (sorted) hash to the file.