Linux下uniq命令详解
2940 点击·0 回帖
![]() | ![]() | |
![]() | uinq是unique的简写。 一.介绍 功能说明:检查及删除文本文件中重复出现的行列 二.语法 语 法:uniq [-cdu][-f<栏位>][-s<字符位置>][-w<字符位置>][--help][--version][输入文件][输出文件] 补充说明:uniq可检查文本文件中重复出现的行列。 三.常用参数: -c 显示输出中,在每行行首加上本行在文件中出现的次数(count)。它可取代-u加-d。 -d 只显示重复行。 -u 只显示文件中不重复的各行。 -n 前n个字段与每个字段前的空白一起被忽略。一个字段是一个非空格、非制表符的字符串,彼此由制表符和空格隔开(字段从0开始编号)。 +n 前n个字符被忽略,之前的字符被跳过(字符从0开始编号)。 -f n 与-n相同,这里n是字段数。 -s n 与+n相同,这里n是字符数。 四.实例详解 uniq.txt的原文如下: [root@umail39 tmp]#cat uniq.txt this is a test this is a test This is a test i love you i love you we are good this is a pen i do not know this is a pen www.atcpu.com 1.在每行前加上表示相应行目出现次数,但只会检查相邻重复的行。 [root@umail39 tmp]#uniq -c uniq.txt 2 this is a test 1 This is a test 2 i love you 1 we are good 1 this is a pen 1 i do not know 1 this is a pen 2.,-f 1 忽略了第一列,检查重复从第二字段开始的,检查的时候,不区分大小写. [root@umail39 tmp]#uniq -f 1 -c uniq.txt 3 this is a test 2 i love you 1 we are good 1 this is a pen 1 i do not know 1 this is a pen 3.检查的时候,不考虑前4个字符 [root@umail39 tmp]#uniq -s 4 -c uniq.txt 3 this is a test 2 i love you 1 we are good 1 this is a pen 1 i do not know 1 this is a pen 4.去重复的项,然后全部显示出来 [root@umail39 tmp]#uniq -u uniq.txt This is a test we are good this is a pen i do not know this is a pen 5.对每行第2个字符以后的内容不作检查 [root@umail39 tmp]#uniq -w 2 -c uniq.txt 2 this is a test 1 This is a test 2 i love you 1 we are good 1 this is a pen 1 i do not know 1 this is a pen | |
![]() | ![]() |