首页 > 系统服务 > 详细

linux下uniq和tee命令

时间:2016-03-10 01:51:36      阅读:269      评论:0      收藏:0      [点我收藏+]

uniq 去重复,并且还能计算出几行重复的。
uniq -c 统计重复的行数,将重复的数写在前面,

uniq是比较笨的,只有相邻的两行才能去重复。

[root@one ~]# cat test.txt
1
11
2
2
4
54
4
7
g
eqwe
qw
2
[root@one ~]# uniq -c test.txt
      1 1
      1 11
      2 2
      1 4
      1 54
      1 4
      1 7
      1 g
      1 eqwe
      1 qw
      1 2


这样并不能去重复,要想全部去重复,那么去重复前需要将文件排序 

sort 1.txt | uniq -c

[root@one ~]# sort test.txt |uniq -c
      1 1
      1 11
      3 2
      2 4
      1 54
      1 7
      1 eqwe
      1 g
      1 qw

tee后跟文件名,类似于重定向,直接覆盖指定文件,然后将文件内容显示出来;

[root@one ~]# echo "11111"|tee test.txt
11111
[root@one ~]# cat test.txt
11111

-a选项,类似与追加重定向,附加在既有文件内容的后面。

[root@one ~]# cat test.txt
11111
[root@one ~]# echo "11111"|tee -a test.txt
11111
[root@one ~]# cat test.txt
11111
11111


linux下uniq和tee命令

原文:http://1024079574.blog.51cto.com/10921986/1749329

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!