使用uniq命令得到不重复的行
现有文件如下:
—————————————————
my friends, chenhong
my friends, chenhong
my friends, chenhong
my teacher, liyong
my teacher, liyong
my teacher, liyong
my father, wuzhongyi
my father, wuzhongyi
my father, wuzhongyi
my sister, wushiying
my sister, wushiying
my sister, wushiying
—————————————————
现在欲把文件变成如下:
—————————————————
my friends, chenhong
my teacher, liyong
my father, wuzhongyi
my sister, wushiying
—————————————————

命令:
[cc lang=”bash”]uniq file[/cc]

使用sort和awk删除存在特定列重复的行

文件如下:
———————-

aa  cc  dd ee

11 34  45 22

bb  cc dd ee

ff cc dd ee

———————-
现在欲把文件变成如下:
———————-

aa  cc  dd ee

11 34  45 22

———————-
[cc lang=”bash”]sort -k2,3 |awk ‘{if(str!=$2$3){str=$2$3;print}}’[/cc]

http://bbs.chinaunix.net/viewthread.php?tid=473706
http://www.linuxsir.org/bbs/thread132848.html

作者简介

Chun-Hui Gao is a Research Associate at Huazhong Agricultural University.

重复使用

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The source code is licensed under MIT. The full source is available at https://github.com/yihui/hugo-prose.

欢迎修订

如果您发现本文里含有任何错误(包括错别字和标点符号),欢迎在本站的 GitHub 项目里提交修订意见。

引用本文

如果您使用了本文的内容,请按照以下方式引用:

gaoch (2011). 使用shell删除文本中的重复行. BIO-SPRING. /post/2011/07/16/2011-07-16-remove-dup-lines/

BibTeX citation

@misc{
  title = "使用shell删除文本中的重复行",
  author = "gaoch",
  year = "2011",
  journal = "BIO-SPRING",
  note = "/post/2011/07/16/2011-07-16-remove-dup-lines/"
}