当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > linux 操作系统 uniq命令的说明和使用

Unix/Linux
遭遇MYSON MTD803F
局域网虚拟服务器的工作模式
NFS Server+NFS Client配置
SmoothWall 防火墙(软路由)安装+配置详解
让Linux NAT firewall支持MSN Messenger
[精华] 使用 IGD(Upnp)解決 MSN 語音聊天問題
UPnP on your Linux 2.4 firewall how-to
Modules的概念及使用
Fedora 可以用了,下一步计划
Linux下的库(上)--如何使用非标准库
python遍历文件夹
PHP测试题
我的vimrc
自己写的备份服务器的脚本
破XP开机密码
调谐LINUX网络性能之调试工具篇
由vmstat看服务器
通过红旗4.1plus管窥红旗5.0(多图)
安装ff的误区+解决方法
网络安全:iptable

Unix/Linux 中的 linux 操作系统 uniq命令的说明和使用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-15   浏览: 102 ::
收藏到网摘: n/a

uniq命令的作用:显示唯一的行,对于那些连续重复的行只显示一次!

接下来通过实践实例说明:

[root@stu100 ~]# cat test
boy took bat home
boy took bat home
girl took bat home
dog brought hat home
dog brought hat home
dog brought hat home

看test文件的内容,可以看到其中的连续重复行

[root@stu100 ~]# uniq test
boy took bat home
girl took bat home
dog brought hat home

uniq命令不加任何参数,仅显示连续重复的行一次

[root@stu100 ~]# uniq -c test
2 boy took bat home
1 girl took bat home
3 dog brought hat home

-c 参数显示文件中每行连续出现的次数。

[root@stu100 ~]# uniq -d test
boy took bat home
dog brought hat home

-d选项仅显示文件中连续重复出现的行。

[root@stu100 ~]# uniq -u test
girl took bat home

-u选项显示文件中没有连续出现的行。

[root@stu100 ~]# uniq -f 2 -s 2 test
boy took bat home

忽略每行的前2个字段,忽略第二个空白字符和第三个字段的首字符,结果at home

[root@stu100 ~]# uniq -f 1 test
boy took bat home
dog brought hat home

忽略每行的第一个字段,这样boy ,girl开头的行看起来是连续重复的行。