删除重复行——perl的效率!

目标:删除ncolog_091019文件中的重复行。
[root@NMRK01 ncolog_DCBJ]# more test
date  >time
sort  ncolog_091019|uniq >091019
date  >>time
[root@NMRK01 ncolog_DCBJ]# more test2
date >>time
perl -n -e 'if ( /^/s*$/){print; next};if (exists($hash{$_})) { next } else { $hash{$_}=1; print }' ncolog_091019 >091019perl
date>>time
#sh  test
#sh  test2
[root@NMRK01 ncolog_DCBJ]# more time
四 11月  5 16:36:36 CST 2009
四 11月  5 16:41:01 CST 2009
四 11月  5 16:44:25 CST 2009
四 11月  5 16:44:38 CST 2009
[root@NMRK01 ncolog_DCBJ]# ll -h
总 用量 11G
-rw-r--r--  1 root root 104M 11月  5 16:41 091019
-rw-r--r--  1 root root 104M 11月  5 16:44 091019perl
-rw-r--r--  1 root root 387M 10月 19 15:03 ncolog_091019
 
结果:sort+uniq 耗时近5分钟;perl用时仅13秒!

你可能感兴趣的:(Date,perl)