NAME
uniq - report or omit repeated lines SYNOPSIS
uniq [OPTION]... [INPUT [OUTPUT]] DESCRIPTION
Filter adjacent matching lines from INPUT (or standard input), writing to OUTPUT (or standard output). With no options, matching lines are merged to the first occurrence. Mandatory arguments to long options are mandatory for short options too. -c, --count
prefix lines by the number of occurrences -d, --repeated
only print duplicate lines -D, --all-repeated[=delimit-method]
print all duplicate lines delimit-method={none(default),prepend,separate} Delimiting is done with blank lines -f, --skip-fields=N
avoid comparing the first N fields -i, --ignore-case
ignore differences in case when comparing -s, --skip-chars=N
avoid comparing the first N characters -u, --unique
only print unique lines -z, --zero-terminated
end lines with byte, not newline -w, --check-chars=N
compare no more than N characters in lines --help display this help and exit --version
output version information and exit A field is a run of blanks (usually spaces and/or TABs), then non-blank characters. Fields are skipped before chars. Note: 'uniq' does not detect repeated lines unless they are adjacent. You may want to sort the input first, or use 'sort -u' without 'uniq'. Also, comparisons honor the rules specified by 'LC_COL‐
LATE'.

以上是man输出。

从最后的note中可以知道当使用uniq进行去重,要求输入重复项是相邻的。这个比较好理解,要求重复项时连续的话可以省去一个hashmap的空间来做统计。为了获得这样的一个输入,可以先对数据进行一个排序操作,这样重复项必然是连续相邻的。

有如下文本文件:

the
day
is
sunny
the
the
sunny
day
is
today
is
sunny
day
UASE CASE 1.

首先对单词内容做一个去重处理(先排序,再去重)

$ sort words.txt | uniq
day
is
sunny
the
today
USE CASE 2.

重复统计:

$ sort words.txt | uniq -c
day
is
sunny
the
today

USE CASE 3.

只输出重复项或者只输出唯一项:

$ sort words.txt | uniq -d
day
is
sunny
the
$ sort words.txt | uniq -u
today

Bash:常用命令工具-uniq的更多相关文章

  1. java jvm常用命令工具

    [尊重原创文章出自:http://www.chepoo.com/java-jvm-command-tools.html] 一.概述 程序运行中经常会遇到各种问题,定位问题时通常需要综合各种信息,如系统 ...

  2. JVM监控和调优常用命令工具总结

    JVM监控和调优 在Java应用和服务出现莫名的卡顿.CPU飙升等问题时总是要分析一下对应进程的JVM状态以定位问题和解决问题并作出相应的优化,在这过程中Java自带的一些状态监控命令和图形化工具就非 ...

  3. Bash:常用命令工具-tr命令

    tr命令可以用来做简单的字符替换与删除,常用的有-d, -s选项.它的替换与删除是按单个字符来的 假设有以下文本: Read from the file words.txt and output th ...

  4. git bash 常用命令

    1.   cd : 切换到哪个目录下, 如 cd e:\fff  切换 E 盘下面的fff 目录. 当我们用cd 进入文件夹时,我们可以使用 通配符*, cd f*,  如果E盘下只有一个f开头的文件 ...

  5. GStreamer基础教程12 - 常用命令工具

    摘要 GStreamer提供了不同的命令行工具用于快速的查看信息以及验证Pipeline的是否能够正确运行,在平时的开发过程中,我们也优先使用GStreamer的命令行工具验证,再将Pipeline集 ...

  6. [jvm] -- 监控和调优常用命令工具篇

    jps:java版本的ps,查看进程的信息 jps -l 输出jar包路径,类全名 jps -m 输出main参数 jps -v 输出JVM参数 jinfo:是用来查看JVM参数和动态修改部分JVM参 ...

  7. git Bash常用命令

    1.Construct ssh key (If you want to commit to git server via THIS COMPUTER) git config --global user ...

  8. java 常用命令工具

    1. jmap (1)分析堆信息 jmap -heap java_pid (2) 导出 java进程 5460 的堆内容 到文件 heap.map ,然后使用 jhat 分析 jmap -dump:l ...

  9. /bin/bash 常用命令

    ls -a 查看一切文件 ls -l 查看目录文件信息 clear 清屏(信息保留屏幕) reset 清屏(所有信息) ls *.txt 查看所有txt文件 wc 统计文件 -l 行数: - c 统计 ...

随机推荐

  1. Backtracking-401. Binary Watch

    A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...

  2. create session 参数介绍

    Create Session alias, url, headers={}, cookies=None, auth=None, timeout=None, proxies=None, verify=F ...

  3. nginx请求频率限制模块ngx_http_limit_req_module

    模块: ngx_http_limit_req_module 作用: 限制客户端请求频率,防止恶意攻击 配置示例: http { limit_req_zone $binary_remote_addr z ...

  4. linux,软链接配置node,npm全局命令

    sudo ln -s /usr/local/bin/node   /bin/node sudo ln -s /usr/local/bin/npm    /bin/npm 这样配置后,在root下和别的 ...

  5. Opserver 初探一《Opserver的搭建》

    Opserver 是Stack Overflow的开源监控产品.stackoverflow网站是基于asp.net开发的,具体采用的软硬件配置可以查看<StackOverflow 这么大,究竟用 ...

  6. sublime text ubuntu

    { "color_scheme": "Packages/User/SublimeLinter/Dawn (SL).tmTheme", "font_fa ...

  7. SELECT列表中的标量子查询

    发现了一种表连接新的写法,以前还没有这样写过或者见别人写过.跟同学聊天他们公司却很多人这样写,看来真的要学学sql了 表 CREATE TABLE `t_book` ( `FId` ) NOT NUL ...

  8. Android_PullListView

    ListView 下拉刷新,上拉加载更多的原理: (1)主要是onScroll()方法和onTouchEvent()方法,先是onTouchEvent()的ACTION_DOWN,然后是 ACTION ...

  9. 安装微软dynamics AX2012R3-AOS(含域服务器的安装)

    安装之前首先要确保硬盘可用量>60G,内存要在7G及以上,我是在Mac里装的虚拟机,分配了7G内存(我的电脑总共才8G),编译CIL内存占用到了98% 一.Server 2016新建域控服务器 ...

  10. 微信小程序开发-概述

    微信小程序开发-概述 一.小程序申请&APPID 登录微信平台申请成为小程序开发者,小程序不可直接使用服务号或订阅号的AppID,需要登录微信公众平台管理后台,在网站的"设置&quo ...