- 浏览: 258920 次
- 性别:
- 来自: 天津
文章分类
最新评论
-
1260533105:
uncaught invalidstateerror:Fail ...
WebSocket -
sh747665463:
压力好大啊
【转】如果你不知道接下去学什么,就看这个
一、uniq干什么用的
linux下去除文本重复行的命令之一。从网上看来两个注意事项:
1,对文本操作时,它一般会和sort命令进行组合使用,因为uniq 不会检查重复的行,除非它们是相邻的行。如果您想先对输入排序,使用sort -u。
2,对文本操作时,若域中为先空字符(通常包括空格以及制表符),然后非空字符,域中字符前的空字符将被跳过
二、uniq参数说明
用法:uniq [选项]... [文件]
从输入文件或者标准输入中筛选相邻的匹配行并写入到输出文件或标准输出。
不附加任何选项时匹配行将在首次出现处被合并。
长选项必须使用的参数对于短选项时也是必需使用的。
-c, --count //在每行前加上表示相应行目出现次数的前缀编号
-d, --repeated //只输出重复的行
-D, --all-repeated //只输出重复的行,不过有几行输出几行
-f, --skip-fields=N //-f 忽略的段数,-f 1 忽略第一段
-i, --ignore-case //不区分大小写
-s, --skip-chars=N //根-f有点像,不过-s是忽略,后面多少个字符 -s 5就忽略后面5个字符
-u, --unique //去除重复的后,全部显示出来,根mysql的distinct功能上有点像
-z, --zero-terminated end lines with 0 byte, not newline
-w, --check-chars=N //对每行第N 个字符以后的内容不作对照
--help //显示此帮助信息并退出
--version //显示版本信息并退出
三,测试文本文件uniqtest
- this is a test
- this is a test
- this is a test
- i am tank
- i love tank
- i love tank
- this is a test
- whom have a try
- WhoM have a try
- you have a try
- i want to abroad
- those are good men
- we are good men
四,实例详解
- [zhangy@BlackGhost mytest]$ uniq -c uniqtest
- 3 this is a test
- 1 i am tank
- 2 i love tank
- 1 this is a test //和第一行是重复的
- 1 whom have a try
- 1 WhoM have a try
- 1 you have a try
- 1 i want to abroad
- 1 those are good men
- 1 we are good men
从上例子中我们可以看出,uniq的一个特性,检查重复行的时候,只会检查相邻的行。重复数据,肯定有很多不是相邻在一起的。
- [zhangy@BlackGhost mytest]$ sort uniqtest |uniq -c
- 1 WhoM have a try
- 1 i am tank
- 2 i love tank
- 1 i want to abroad
- 4 this is a test
- 1 those are good men
- 1 we are good men
- 1 whom have a try
- 1 you have a try
这样就可以解决上个例子中提到的问题
- [zhangy@BlackGhost mytest]$ uniq -d -c uniqtest
- 3 this is a test
- 2 i love tank
uniq -d 只显示重复的行
- [zhangy@BlackGhost mytest]$ uniq -D uniqtest
- this is a test
- this is a test
- this is a test
- i love tank
- i love tank
uniq -D 只显示重复的行,并且把重复几行都显示出来。他不能和-c一起使用
- [zhangy@BlackGhost mytest]$ uniq -f 1 -c uniqtest
- 3 this is a test
- 1 i am tank
- 2 i love tank
- 1 this is a test
- 2 whom have a try
- 1 you have a try
- 1 i want to abroad
- 2 those are good men //只有一行,显示二行
在这里those只有一行,显示的却是重复了,这是因为,-f 1 忽略了第一列,检查重复从第二字段开始的。
- [zhangy@BlackGhost mytest]$ uniq -i -c uniqtest
- 3 this is a test
- 1 i am tank
- 2 i love tank
- 1 this is a test
- 2 whom have a try //一个大写,一个小写
- 1 you have a try
- 1 i want to abroad
- 1 those are good men
- 1 we are good men
检查的时候,不区分大小写
- [zhangy@BlackGhost mytest]$ uniq -s 4 -c uniqtest
- 3 this is a test
- 1 i am tank
- 2 i love tank
- 1 this is a test
- 3 whom have a try //根上一个例子有什么不同
- 1 i want to abroad
- 1 those are good men
- 1 we are good men
检查的时候,不考虑前4个字符,这样whom have a try 就和 you have a try 就一样了。
- [zhangy@BlackGhost mytest]$ uniq -u uniqtest
- i am tank
- this is a test
- whom have a try
- WhoM have a try
- you have a try
- i want to abroad
- those are good men
- we are good men
去重复的项,然后全部显示出来
- [zhangy@BlackGhost mytest]$ uniq -w 2 -c uniqtest
- 3 this is a test
- 3 i am tank
- 1 this is a test
- 1 whom have a try
- 1 WhoM have a try
- 1 you have a try
- 1 i want to abroad
- 1 those are good men
- 1 we are good men
对每行第2个字符以后的内容不作检查,所以i am tank 根 i love tank就一样了。
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/shell/1022.html
发表评论
-
转:Linux内核参数详解
2018-07-20 17:34 447https://blog.csdn.net/yueguan ... -
ipmitool
2018-07-17 17:53 715一、开关机,重启 1. ... -
awk 分组统计
2018-04-15 09:27 1292cat * |grep 'java.lang.ClassNot ... -
numa关闭
2016-10-20 09:54 1511zone_reclaim_mode参数为1,numa并没有关 ... -
shell单引号,双引号,反引号与反斜杠
2016-07-03 09:40 1163单引号:强调是什么就是什么不替换任何东西,会忽略任何引用值, ... -
shell 判断条件
2016-07-03 09:26 383前言: 无论什么编程语言都离不开条件判 ... -
转:linux 文件系统IO性能优化
2016-05-23 08:53 941对于LINUX SA来说,服 ... -
yum install 安装路径
2016-03-08 19:07 587一般是 /usr/local 一般一个软件是要复制多个文件 ... -
转:linux系统mysql安装后文件分布情况
2016-01-19 20:31 0MySQL安装完成后不象SQL Server默认安装在一个目 ... -
shell控制语句
2016-01-09 09:50 451linux shell有一套自己的流程控制语句,其中包括条件 ... -
shell for 循环
2016-01-09 09:40 0关于shell中的for循环用法很多,一直想总结一下,今天网 ... -
posrt 排序工具并行工作--快
2012-11-05 14:28 856一个文件n列,假设需要按照文件的第2列排序,第二列是in ... -
清理linux 系统缓存
2012-10-31 16:52 888echo 3 > /proc/sys/vm/drop_c ... -
关闭SELinux
2012-07-22 19:13 0关闭SELinux的方法: 修改/etc/seli ... -
grep+sed 全文件夹替换
2012-06-17 21:25 1306grep aaa -rl ./test |xargs s ... -
vim 查找替换
2012-06-04 16:58 866vi/vim 中可以使用 :s ... -
vi常用命令
2012-05-22 20:11 8631、复制多行,并粘贴 ... -
linux多文件替换关键字
2012-06-04 16:57 993现在网上这样的方法只有两种,一种是Mahuinan法,一种是S ... -
TCP 参数
2012-01-16 15:25 2411net.ipv4.tcp_max_tw_buckets ... -
转:linux下tomcat自启动
2011-11-24 17:23 9481. 准备 RedHat 9.0(原则上 RH7,8,9 ...
相关推荐
我们应当注意的是,它和sort的区别,sort只要有重复行,它就去除,而uniq重复行必须要连续,也可以用它忽略文件中的重复行。 语法格式:uniq [参数] [文件] 常用参数: -c 打印每行在文本中重复出现的次数 -d ...
linux下uniq和sort命令用法详解.docx
linux下uniq和sort命令用法.docx
LINUX处理文本命令 处理文本和文本文件的命令 一. sort 文件排序, 通常用在管道中当过滤器来使用. 这个命令可以依据指定的关键字或指定的字符位置, 对文件行进行排序. 使用-m选项, 它将会合并预排序的输入文件. 想...
详细介绍linux下用于处理文本文件分类、合并、分割操作的工具 如:sort、uniq、join、cut、paste、split
主要介绍了Linux命令 sort、uniq、tr工具详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
uniq命令的作用:显示唯一的行,对于那些连续重复的行只显示一次! 本文将通过实践实例说明
Linux笔记——命令:Sort,uniq,join,cut,paste,split Linux笔记——shell基础:变量&本地变量&位置变量&特定变量参数 Linux笔记——条件测试test Linux笔记——控制流 Linux笔记——shell补充:参数传递&函数等 Linux...
Shell中的sort和uniq命令 sort :通常用来排序 uniq :通常对重复字符进行处理 sort -n sort -r sort -u 去重,u: unique(独一无二的) sort -o 指定输出文件 sort -t 指定分隔符 sort -k 指定列排序(配合-t使用) ...
linux常用命令大全 Linux系统提供了大量的命令用于文件管理、系统配置、网络... uniq:报告或省略重复的行。 cut:从每行中删除指定的部分。 paste:合并文件的行。 sed / awk:强大的文本处理工具,用于模式扫描和
linux 核心命令源码(cp mv cat chgrp chown cut date df du echo env expand expr find force fs group head hostname join kill link ls mkdir mv nice od paste printf ptx rm selinux seq sleep sort split stat...
主要涉及shell脚本中文本处理常见命令,diff/patch查找文本差异,字符串截取cut、tr、uniq等
因为不耐烦反复的查,索性自己总结了一个pdf,里面包括常用的linux命令,包括gcc,grep,tar,sed,find,screen,nohup,scp等,另外还有一些常用的文本处理命令如cat,split,head,tail,uniq,wc,more,less等。
主要给大家介绍了关于在linux中利用lsof命令如何查看文件打开情况的相关资料,文中通过示例代码以及图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出。如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序。 sort语法 [root@www~]# sort [-fbMnrtuk] ...
从文件和目录操作到用户管理等。 ls cp cut head stat sort uniq awk grep sed chmod chown useradd groupadd mount 等
Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。 Linux命令分类 这里存放Linux 命令大全并不全,你可以通过linux-command来搜索,它是把 command 目录里面搜集的...
一、操作系统概述 1、 操作系统 2、 不同应用利于的主流操作系统二、系统安装 1、安装VM虚拟机 1.1 简要介绍 1.2 配置网卡 ...2.8.8 uniq命令 2.8.9 tee命令 2.8.10 tr命令 2.8.11 split命令 2.8.12 awk命令
linux下大部分常用命令源码,偶正要开始学习-_- base64.c basename.c c99-to-c89.diff cat.c chcon.c chgrp.c chmod.c chown.c chown-core.c chown-core.h chroot.c cksum.c comm.c copy.c cp.c cp-hash.c csplit.c ...
Linux命令大全(CHM格式离线版) Linux命令大全(修改版) 进行重新编译的说明 文件传输 bye ftp ftpcount ftpshut ftpwho ncftp tftp uucico uucp uupick uuto 备份压缩 ar bunzip2 bzip2 bzip2recover compress cpio ...