linux - 有没有办法按列 'uniq'?

我有一个这样的 .csv 文件:

stack2@domain.example,2009-11-27 01:05:47.893000000,domain.example,127.0.0.1
overflow@domain2.example,2009-11-27 00:58:29.793000000,domain2.example,255.255.255.0
overflow@domain2.example,2009-11-27 00:58:29.646465785,domain2.example,256.255.255.0
...

我必须从文件中删除重复的电子邮件(整行)(即上面示例中包含 overflow@domain2.example 的行之一)。如何仅在字段 1(以逗号分隔)上使用 uniq?根据 manuniq 没有列选项。

我尝试了 sort | uniq 但它不起作用。

最佳答案

sort -u -t, -k1,1 file
  • -u 表示唯一
  • -t, 所以逗号是分隔符
  • -k1,1 用于关键字段 1

测试结果:

overflow@domain2.example,2009-11-27 00:58:29.793000000,xx3.net,255.255.255.0
stack2@domain.example,2009-11-27 01:05:47.893000000,xx2.net,127.0.0.1

关于linux - 有没有办法按列 'uniq'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1915636/

相关文章:

python - 如何在 Django 中的 CharField 上添加占位符?

python - 使用 Python 的 os.path,我如何上一个目录?

python - `ValueError: cannot reindex from a duplic

linux - 如何在bash中创建仅包含十六进制字符而不包含空格的文件的十六进制转储?

linux - 我可以用/etc/hosts 映射一个主机名*和*一个端口吗?

linux - 如何在linux中设置环境变量LD_LIBRARY_PATH

linux - 如何在 Linux 上获得整体 CPU 使用率(例如 57%)

linux - 如何就地对文件进行排序?

python - 在 Python 中以编程方式生成视频或动画 GIF?

python - 从 pandas.DataFrame 中选择复杂的标准