全部博文(2065)
分类: LINUX
2010-04-10 21:52:26
$ cat happybirthday.txt
Happy Birthday to You!
Happy Birthday to You!
Happy Birthday Dear Tux!
Happy Birthday to You!
$ sort happybirthday.txt
Happy Birthday Dear Tux!
Happy Birthday to You!
Happy Birthday to You!
Happy Birthday to You!
$ sort happybirthday.txt | uniq
Happy Birthday Dear Tux!
Happy Birthday to You!
如果您希望您的工作轻松点,比如只显示唯一的或重复的行,那么该怎么办呢?您可以用-u
(唯一)和-d
(重复)选项来做到这一点,例如:
$ sort happybirthday.txt | uniq -u 将不重复的行给显示出来!
Happy Birthday Dear Tux!
$ sort happybirthday.txt | uniq -d 将重复的行给显示出来!这样我就可以马上知道哪条记录重复
Happy Birthday to You!
笔记:如果你想使用uniq命令 得先做一下sort操作。然后再管道就行!