有没有办法按列'uniq'? [英] Is there a way to 'uniq' by column?
本文介绍了有没有办法按列'uniq'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的 .csv 文件:
I have a .csv file like this:
stack2@example.com,2009-11-27 01:05:47.893000000,example.net,127.0.0.1
overflow@example.com,2009-11-27 00:58:29.793000000,example.net,255.255.255.0
overflow@example.com,2009-11-27 00:58:29.646465785,example.net,256.255.255.0
...
我必须从文件中删除重复的电子邮件(整行)(即上面示例中包含 overflow@example.com
的行之一).如何仅在字段 1(以逗号分隔)上使用 uniq
?根据 man
,uniq
没有列选项.
I have to remove duplicate e-mails (the entire line) from the file (i.e. one of the lines containing overflow@example.com
in the above example). How do I use uniq
on only field 1 (separated by commas)? According to man
, uniq
doesn't have options for columns.
我用 sort | 尝试了一些东西uniq
但它不起作用.
I tried something with sort | uniq
but it doesn't work.
推荐答案
sort -u -t, -k1,1 file
-u
表示唯一-t,
所以逗号是分隔符-k1,1
用于关键字段 1-u
for unique-t,
so comma is the delimiter-k1,1
for the key field 1
测试结果:
overflow@domain2.com,2009-11-27 00:58:29.793000000,xx3.net,255.255.255.0
stack2@domain.com,2009-11-27 01:05:47.893000000,xx2.net,127.0.0.1
这篇关于有没有办法按列'uniq'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文