zoukankan      html  css  js  c++  java
  • uniq 去除重复命令使用方法介绍

    原文地址

    Linux Shell学习:uniq命令使用方法介绍uniq命令的作用:显示唯一的行,对于那些连续重复的行只显示一次!接下来通过实践实例说明. [关键字] Linux Shell uniq

    看test.txt文件的内容,可以看到其中的连续重复行

    [root@hexu.org ~]# cat test.txt
    boy took bat home
    boy took bat home
    girl took bat home
    dog brought hat home
    dog brought hat home
    dog brought hat home


    uniq命令不加任何参数,仅显示连续重复的行一次

    [root@hexu.org ~]# uniq test.txt
    boy took bat home
    girl took bat home
    dog brought hat home


    -c 参数显示文件中每行连续出现的次数。

    [root@hexu.org ~]# uniq -c test.txt
    2 boy took bat home
    1 girl took bat home
    3 dog brought hat home


    -d选项仅显示文件中连续重复出现的行。

    [root@hexu.org ~]# uniq -d test.txt
    boy took bat home
    dog brought hat home


    -u选项显示文件中没有连续出现的行。

    [root@hexu.org ~]# uniq -u test.txt
    girl took bat home


    忽略每行的前2个字段,忽略第二个空白字符和第三个字段的首字符,结果at home

    [root@hexu.org ~]# uniq -f 2 -s 2 test.txt
    boy took bat home


    忽略每行的第一个字段,这样boy ,girl开头的行看起来是连续重复的行。

    [root@hexu.org ~]# uniq -f 1 test.txt
    boy took bat home
    dog brought hat home


  • 相关阅读:
    100722B
    6-排列
    5-分西瓜差最小(背包 || dfs)
    4-计算九位数以内各个位数字和为s的种类
    3-计算01串
    2-计算星期几(基姆拉尔森计算公式)
    1-作业题构成单调曲线的点数最多
    12-分苹果(递归)
    11-砝码分配(利用3进制)
    10-约瑟夫环的几种解法
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2455046.html
Copyright © 2011-2022 走看看