Dev@Free

zJun's Tech Weblog

Find duplicate records in text file

Example:
abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452
abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452
tas 3420 3562 2123 1343 2176 7654 3252 8765 5643 3452
aer 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452
tas 3420 3562 2123 1343 2176 7654 3252 8765 5643 3452

UNIX:

display the no of occurance and the record
> sort f1.txt|uniq -c
   2 abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452
   1 aer 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452
   2 tas 3420 3562 2123 1343 2176 7654 3252 8765 5643 3452

display only the duplicate records
> sort f1.txt|uniq -d
abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452
tas 3420 3562 2123 1343 2176 7654 3252 8765 5643 3452

display distinct records
> sort f1.txt|uniq
abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452
aer 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452
tas 3420 3562 2123 1343 2176 7654 3252 8765 5643 3452

Reference:
Shell: How To Remove Duplicate Text Lines

Windows:

Notepad++ can sort by line, and remove the duplicate lines at the same time.
  1. Open the menu under: TextFX-->TextFX Tools
  2. Make sure "sort outputs only unique..." is checked
  3. select a block of text (ctrl-a to select the entire document).
  4. click "sort lines case sensitive" or "sort lines case insensitive"

posted on 2012-04-11 12:10 zJun's帛罗阁 阅读(448) 评论(0)  编辑  收藏 所属分类: 开发环境


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2012年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

统计

常用链接

留言簿(15)

随笔分类

随笔档案

相册

收藏夹

博客

文档

站点

论坛

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜