uniq命令可以去除排序过的文件中的重复行,因此uniq经常和sort合用。也就是说,为了使uniq起作用,所有的重复行必须是相邻的。

uniq语法

[root@www ~]# uniq [-icu]
选项与参数:
-i :忽略大小写字符的不同;
-c :进行计数
-u :只显示唯一的行

testfile的内容如下

cat testfile
hello
world
friend
hello
world
hello

直接删除未经排序的文件,将会发现没有任何行被删除

#uniq testfile
hello
world
friend
hello
world
hello

排序文件,默认是去重

#cat words | sort |uniq
friend
hello
world

排序之后删除了重复行,同时在行首位置输出该行重复的次数

#sort testfile | uniq -c
1 friend
3 hello
2 world

仅显示存在重复的行,并在行首显示该行重复的次数

#sort testfile | uniq -dc
3 hello
2 world

仅显示不重复的行

sort testfile | uniq -u
friend

uniq命令 (转)的更多相关文章

  1. Linux uniq命令

    200 ? "200px" : this.width)!important;} --> 介绍 uniq命令是一个文本去重命令,它能对标准输入和文本文件进行去重操作,并且能将结 ...

  2. uniq命令注意事项,检查重复行的时候,只会检查相邻的行。

    今天在使用uniq命令统计数量时,uniq -c总是得不到想要的效果,相同的行没有合并,例如 后来在http://ju.outofmemory.cn/entry/78365才看到,原来uniq检查重复 ...

  3. [shell基础]——uniq命令

    uniq命令常见选项      去除重复行      -u  显示不重复的行      -d  显示有重复的行      -c  打印每一行重复的次数 测试文本内容如下: # cat 4.txt 11 ...

  4. uniq 命令

    uniq 命令 文字 uniq是LINUX命令 用途 报告或删除文件中重复的行. 语法 uniq [ -c | -d | -u ] [ -f Fields ] [ -s Characters ] [ ...

  5. Linux Shell脚本入门--Uniq命令

    uniq uniq命令可以去除排序过的文件中的重复行,因此uniq经常和sort合用.也就是说,为了使uniq起作用,所有的重复行必须是相邻的. uniq语法 [root@www ~]# uniq [ ...

  6. Linux之uniq命令

    uniq - report or omit repeated lines  省去重复的行 参数: -i  忽略大小写字符的不同 -c  对重复的行进行记数 注意:uniq命令只会对相邻的重复的行进行去 ...

  7. Linux uniq 命令

    Linux uniq 命令  Linux 命令大全 Linux uniq 命令用于检查及删除文本文件中重复出现的行列,一般与 sort 命令结合使用. uniq 可检查文本文件中重复出现的行列. 语法 ...

  8. sort与uniq命令详解

    1.sort的作用 (排序) sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出. 如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行 ...

  9. [20171205]uniq命令的输入输出.txt

    [20171205]uniq命令的输入输出.txt --//前几天遇到XXD与通配符问题,链接http://blog.itpub.net/267265/viewspace-2147702/--//今天 ...

  10. linux shell 脚本攻略学习8---md5校验,sort排序,uniq命令详解

    一.校验与核实 目前最为出名的校验技术是md5sum和sha1sum,它们对文件内容使用相应的算法来生成校验和. 举例: amosli@amosli-pc:~/learn$ md5sum text.t ...

随机推荐

  1. Xilinx Platform Usb Cable

    Key Features High-performance FPGA configuration and PROM/CPLD programming Includes innovative FPGA- ...

  2. BeeProg2C Extremely fast universal USB interfaced programmer

    http://www.elnec.com/products/universal-programmers/beeprog2c/ FPGA based totally reconfigurable 48  ...

  3. How to Find Processlist Thread id in gdb !!!!!GDB 使用

    https://mysqlentomologist.blogspot.jp/2017/07/           Saturday, July 29, 2017 How to Find Process ...

  4. %( $# > 1 %? if (tid() in trace) %) 是什么意思

    http://blog.csdn.net/sunnybeike/article/details/7769663 http://blog.163.com/digoal@126/blog/static/1 ...

  5. mysql文件目录详解 LINUX

    http://www.cnblogs.com/yjf512/archive/2012/12/11/2813398.html

  6. C++空类产生哪些成员函数 || C++类可以自动生成的6个成员函数

    class Empty {     public:     Empty(); // 缺省构造函数     Empty( const Empty& ); // 拷贝构造函数     ~Empty ...

  7. 七问C#关键字const和readonly

    const和readonly经常被用来修饰类的字段,两者有何异同呢? const 1.声明const类型变量一定要赋初值吗? --一定要赋初值 public class Student { publi ...

  8. 常见的Hadoop十大应用误解

    常见的Hadoop十大应用误解 1.        (误解) Hadoop什么都可以做 (正解) 当一个新技术出来时,我们都会去思考它在各个不同产业的应用,而对于平台的新技术来说,我们思考之后常会出现 ...

  9. CoreAudio实现录音播音和扬声器听筒模式的切换

    本例子使用Core Audio实现类似于微信的音频对讲功能,可以录音和播放并且实现了听筒模式和扬声器模式的切换.录音主要使用AVAudioRecorder类来实现录音功能,播放则使用AVAudioPl ...

  10. [14] 齿轮(Gear Wheel)图形的生成算法

    顶点数据的生成 bool YfBuildGearwheelVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices ...