昨日举荐:每天学一个 Linux 命令(32):sort

命令简介

uniq 命令用于去除文件中反复行,个别与 sort 命令联合应用。

语法格局

uniq [选项] [规范输出 [输入]]uniq [OPTION] [INPUT [OUTPUT]]
输出文件 #指定要去除的反复行文件。如果不指定该项,则从规范读入输入文件 #指定要去除反复行后的内容要写入的输入文件。如果不指定此项,则将内容显示到规范输出设备(显示终端)。

选项阐明

-c  #在每列旁边显示该行反复呈现的次数-d  #只显示反复呈现的行与列-f  #疏忽比拟指定的字段-s  #疏忽比拟指定的字符-i  #不辨别大小写的比拟-u  #只显示呈现过一次的行与列-w  #指定要比拟的字符-z  #用0字节(NULL)代替换行符--help    #显示帮忙信息并退出--version #显示版本信息并退出

利用举例

#删除反复行[root@centos7 ~]# cat test.txt This is a test lineThis is a test lineThis is a test lineThis is also a test lineThis is also a test lineThis is also also a test line[root@centos7 ~]# uniq test.txt This is a test lineThis is also a test lineThis is also also a test line[root@centos7 ~]# sort test.txt | uniqThis is also also a test lineThis is also a test lineThis is a test line#只显示繁多行[root@centos7 ~]# uniq -u test.txtThis is also also a test line[root@centos7 ~]# sort test.txt |uniq -uThis is also also a test line#统计各行在文件中呈现的次数[root@centos7 ~]# sort test.txt |uniq -c      1 This is also also a test line      2 This is also a test line      3 This is a test line#在文件中找出反复的行[root@centos7 ~]# sort test.txt |uniq -dThis is also a test lineThis is a test line

每天学一个 Linux 命令(30):cut

每天学一个 Linux 命令(31):md5sum