linux uniq命令

消除重复的内容
只能用于已经排过序的数据输入,经常与sort命令结合起来使用
例如:
[root@localhost test]# cat file1.txt 
bash
foss
hack
hack
[root@localhost test]# uniq file1.txt 
bash
foss
hack
[root@localhost test]# sort file1.txt | uniq    #去掉了重复行
bash
foss
hack
[root@localhost test]# uniq -u file1.txt                  -u, --unique:only print unique lines
bash
foss
[root@localhost test]# sort file1.txt | uniq -c         -c , --count : 计数
      1 bash
      1 foss
      2 hack
[root@localhost test]# sort file1.txt | uniq -d              -d,repeated:重复了的
hack

uniq的-s,-w选项:
-s:指定可以跳 过前N个字符
-w:指定用于比较的最大字符数
例,只将每列的第三四个字母进行操作:
[root@localhost test]# cat data.txt 
u:01:ha
d:01:lu
a:02:fu
c:02:bo
[root@localhost test]# sort data.txt | uniq -s 2 -w 2
a:02:fu
d:01:lu

uniq与xargs的结合使用
下面的命令会删除所有的文件,而这些文件的名字是从data.txt中读取出来的
uniq data.txt | xargs rm

$$:是当前运行的进程ID。
[root@localhost test]# echo $$
20967
[root@localhost test]# ps afx | grep 20967
20967  pts/3    Ss     0:00  |   \_ -bash
21425 pts/3    S+     0:00  |       \_ grep 20967
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值