shell入门-uniq去重复和tee重定向

命令:uniq

选项:-c 显示重复数量

说明:去重复,不sort多个功能,显示几个重复

命令:tee

说明:重定向加上双重输出

[root@wangshaojun ~]# cat 2.txt
1
2
2
2
3
3
4
1
ac
5
[root@wangshaojun ~]# uniq 2.txt   ////消除顺序挨着的重复段

1
2
3
4
1
ac
5

///////////////////////////////////////////////////////////////////

-c

[root@wangshaojun ~]# uniq -c 2.txt
1 1
3 2
2 3
1 4
1 1
1 ac
1 5

//////////////////////////////////////////////////////////////////////

 先sort排序,然后uniq显示重复数量

[root@wangshaojun ~]# sort 2.txt |uniq -c
2 1
3 2
2 3
1 4
1 5
1 ac

//////////////////////////////////////////////////////////////////////////

tee

[root@wangshaojun ~]# echo "1111111" > 1.txt
[root@wangshaojun ~]# cat 1.txt
1111111
[root@wangshaojun ~]# echo "1111111" |tee 1.txt  ////输出内容显示在屏幕上
1111111

//////////////////////////////////////////////////////////////////////////////

总结:uniq -c  ////  sort 2.txt | uniq -c   /////    echo “111” |tee 1.txt

原文地址:https://www.cnblogs.com/wangshaojun/p/4966752.html