如何判断文件是否有重复的行?------ sort和uniq搞起
来源:互联网 发布:成龙功夫怎么样 知乎 编辑:程序博客网 时间:2024/05/29 13:30
如何判断文件是否有重复的行? Windows程序员估计要歇菜了, 还是省省吧, linux搞起:
taoge@localhost test> cat a.txt xxx111xxxtaoge@localhost test> wc -l a.txt 3 a.txttaoge@localhost test> taoge@localhost test> taoge@localhost test> taoge@localhost test> sort a.txt | uniq > b.txttaoge@localhost test> wc -l b.txt 2 b.txttaoge@localhost test>
文件由3行变成了2行, 所以a.txt中有重复的行。
再看:
taoge@localhost test> cat c.txt xxx111xxx111taoge@localhost test> wc -l c.txt 3 c.txttaoge@localhost test> taoge@localhost test> taoge@localhost test> taoge@localhost test> sort c.txt | uniq > d.txttaoge@localhost test> wc -l d.txt 3 d.txttaoge@localhost test>
行数没有变化, 可见c.txt中没有重复的行。
当然, 还有更简单的方法,如下:
taoge@localhost test> sort a.txt | uniq -dxxxtaoge@localhost test> sort c.txt | uniq -dtaoge@localhost test>其中, uniq -d是输出duplicate了的行, 也就是重复的行。 要注意, 这是建立在sort后的基础之上的。
在实际开发中, 要经常处理类似问题, 那些还在想怎么去写程序来判断的朋友, 可以换个角度考虑一下了。
0 0
- 如何判断文件是否有重复的行?------ sort和uniq搞起
- 如何运用Sort+Uniq或Sort -u删除重复行
- 如何运用Sort+Uniq或Sort -u删除重复行
- sort uniq 除去重复行
- 简单文本操作之去掉重复行sort 和uniq
- 如何求两个文件的交集、并集和差集?------sort和uniq闪亮登场
- 去重复和排序【sort】【uniq】
- 如何判断数据是否有重复数字
- 判断数据库是否有重复行的问题
- 使用find,xargs,sha1sum,sort,uniq查找重复文件
- Uniq行定位的基础使用和sort
- Linux uniq --去除排序过的文件中的重复行
- 如何判断一个整数数组中是否有重复元素
- 如何判断一个整数数组中是否有重复元素
- uniq和sort的组合运用
- 35 uniq和sort -u的区别
- sort和uniq
- sort和uniq命令
- ecshop二次开发 给商品添加自定义字段
- XMPP的一些资料网站
- C语言字符串操作总结大全(超详细)
- 两个比较好的css面试题。第一天关于z-index
- Hibernate Mysql事务与隔离级别
- 如何判断文件是否有重复的行?------ sort和uniq搞起
- 用CheckBox实现自定义RatingBar
- Web负载均衡的几种实现方式
- linux多进程操作demon
- Study in Coursera Before you study abroad
- VMware 11 安装 ios 10 问题总结
- oracle查询所有表和字段
- 一些术语单词
- android-Supporting Tablets and Handsets