首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >每天学一个 Linux 命令(33):uniq

每天学一个 Linux 命令(33):uniq

作者头像
民工哥
发布2021-02-23 16:39:05
发布2021-02-23 16:39:05
8800
举报

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

命令简介

uniq 命令用于去除文件中重复行,一般与 sort 命令结合使用。

语法格式

代码语言:javascript
复制
uniq [选项] [标准输入 [输出]]
uniq [OPTION] [INPUT [OUTPUT]]
代码语言:javascript
复制
输入文件 #指定要去除的重复行文件。如果不指定该项,则从标准读入
输出文件 #指定要去除重复行后的内容要写入的输出文件。如果不指定此项,则将内容显示到标准输出设备(显示终端)。

选项说明

代码语言:javascript
复制
-c  #在每列旁边显示该行重复出现的次数
-d  #只显示重复出现的行与列
-f  #忽略比较指定的字段
-s  #忽略比较指定的字符
-i  #不区分大小写的比较
-u  #只显示出现过一次的行与列
-w  #指定要比较的字符
-z  #用0字节(NULL)代替换行符
--help    #显示帮助信息并退出
--version #显示版本信息并退出

应用举例

代码语言:javascript
复制
#删除重复行
[root@centos7 ~]# cat test.txt 
This is a test line
This is a test line
This is a test line
This is also a test line
This is also a test line
This is also also a test line
[root@centos7 ~]# uniq test.txt 
This is a test line
This is also a test line
This is also also a test line
[root@centos7 ~]# sort test.txt | uniq
This is also also a test line
This is also a test line
This is a test line

#只显示单一行
[root@centos7 ~]# uniq -u test.txt
This is also also a test line
[root@centos7 ~]# sort test.txt |uniq -u
This 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 -d
This is also a test line
This is a test line

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-01-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 民工哥技术之路 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 命令简介
  • 语法格式
  • 选项说明
  • 应用举例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档