shell命令之uniq
2017-07-28 19:00
232 查看
uniq,顾名思义是去重,但需注意,它统计的是相邻两行是否重复,因此很多时候会配合sort。
常用参数如下:
举例开始,文件file.txt如下:
1、不加参数的uniq
2、显示不重复的行
3、统计行的次数
4、忽略大小写,并统计重复行次数
5、显示重复行
6、跳过n个域
这里跳过第一个域,所以1至3行跳过this,4至6行跳过i,当whom和whoM被跳过时,这两行被当作一样的,至于接下来的一行,跳过you后,还剩2个空格,和上面两行并不一样,这里需要注意。
7、跳过n个字符
这里跳过前4个字符,所以和上面的例子类似,但是此时whoM have a try 和 you have a try就是一样的了。
常用参数如下:
-u 只显示不重复的行 -c 每行开头显示重复行出现的次数,重复行显示一次 -d 只显示重复行 -i 对大小写不敏感 -f 跳过n个域 -s 跳过n个字符
举例开始,文件file.txt如下:
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
1、不加参数的uniq
uniq file.txt this is a test i am 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
2、显示不重复的行
uniq -u Desktop/test 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
3、统计行的次数
uniq -c file.txt 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
4、忽略大小写,并统计重复行次数
uniq -i -c file.txt 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
5、显示重复行
uniq -d file.txt this is a test i love tank
6、跳过n个域
uniq -f 1 -c file.txt 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
这里跳过第一个域,所以1至3行跳过this,4至6行跳过i,当whom和whoM被跳过时,这两行被当作一样的,至于接下来的一行,跳过you后,还剩2个空格,和上面两行并不一样,这里需要注意。
7、跳过n个字符
uniq -s 4 -c file.txt 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就是一样的了。
相关文章推荐
- 转-Shell笔记——命令:Sort,uniq,join,cut,paste,split
- centos shell基础 alias 变量单引号 双引号 history 错误重定向 2>&1 jobs 环境变量 .bash_history source配置文件 nohup & 后台运行 cut,sort,wc ,uniq ,tee ,tr ,split, paste cat> 2.txt <<EOF 通配符 glob模式 发邮件命令mail 2015-4-8 第十二节课
- shell特殊符号/cut,sort,wc,uniq,tee,tr,split命令
- [SHELL]:uniq 命令详解
- shell特殊符号,cut、sort、wc、uniq、tee、tr、split命令
- shell学习二十天----sort的其他内容以及uniq命令
- shell特殊符号cut命令 sort_wc_uniq命令 tee_tr_split命令 shell特殊符号
- shell特殊符号cut命令 sort_wc_uniq命令 tee_tr_split命令 shell特殊符号
- 几个常用的文本处理shell 命令:find、grep、sort、uniq、sed、awk
- Shell 学习9(uniq命令)
- shell中lsort,uniq,cut,wc,seq命令使用
- 8.10 shell特殊符号cut命令 8.11 sort_wc_uniq命令 8.12 tee_t
- Shell 常用字符处理命令cut/sort/wc/uniq/tee/tr/split
- 5_Shell语言―――文本处理命令之wc、tr、cut、join、sort和uniq
- shell脚本之uniq命令
- 几个常用的文本处理shell 命令:find、grep、xargs、sort、uniq、tr、cut、paste、wc、sed、awk
- 8.10 shell特殊符号cut命令 8.11 sort_wc_uniq命令 8.12 tee_tr_split命令 8.13 shell特殊符号下
- Shell基础之-uniq命令
- Shell基础知识 (3) 之 特殊符号、cut sort wc uniq tee tr split命令
- 8.10 shell特殊符号cut命令 8.11 sort_wc_uniq命令 8.12 tee_tr_split命令 8.13 shell特殊符号下