Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1382319
  • 博文数量: 247
  • 博客积分: 10147
  • 博客等级: 上将
  • 技术积分: 2776
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-24 15:18
文章分类

全部博文(247)

文章存档

2013年(11)

2012年(3)

2011年(20)

2010年(35)

2009年(91)

2008年(87)

我的朋友

分类: LINUX

2008-06-02 20:05:51

要统计各种数据文件,若干记录是否在出现在,大日志文件里,或是jcl,统计某个记录的条数,连接shell,处理为原始的文本数据(从数据库来),操控数据库,shell调用sqlplus,执行sql,perl DBI连接oracle,自动建立目录,消除重复行,排序,等等,用awk,shell,sed,grep,perl乱七八糟的。

发现Perl单独就可以把上面的工作基本全都做了,只要你不嫌麻烦代码。Perl真的挺好玩了,特别是用Perl写的相对比较复杂的数据结构,还有OO

的东西。

    统计数据,要把一个文件里重复的记录删除,看了一眼网上给的答案,大体上就是,排序,之后用uniq,awk

awk '{if ($0!=line) print;line=$0}' file

             

     一位达人用sed写的版本,如下:

          sed -f rmdup.sed yourfile

here is the rmdup.sed sed script:


            #n rmdup.sed - ReMove DUPlicate consecutive lines

             # read next line into pattern space (if not the last line)

$!N

# check if pattern space consists of two identical lines

s/^\(.*\)\n\1$/&/

# if yes, goto label RmLn, which will remove the first line in pattern space

t RmLn

# if not, print the first line (and remove it)

P

# garbage handling which simply deletes the first line in the pattern space

: RmLn

D

use `sort' first. there is no EFFICIENT way of sorting in sed/awk

阅读(1285) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~