首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

shell脚本提取数据

2012-09-13 
shell脚本提取数据求助如下的数据,如何用shell脚本提取出时间和处理的时间:数据::2012/8/4 1:53:9[1130457

shell脚本提取数据求助
如下的数据,如何用shell脚本提取出时间和处理的时间:
数据:
:2012/8/4 1:53:9[1130457408]:(GetAppComments)processing time:5.329000ms
:2012/8/4 1:53:9[1176684864]:(GetAppComments)processing time:4.962000ms
:2012/8/4 1:53:10[1161980224]:(GetAppComments)processing time:5.840000ms
:2012/8/4 1:53:11[1126254912]:(GetAppComments)processing time:5.441000ms
:2012/8/4 1:53:11[1105246528]:(GetAppComments)processing time:5.031000ms
:2012/8/4 1:53:17[1130461504]:(GetAppComments)processing time:5.354000ms
:2012/8/4 1:53:25[1101044032]:(GetAppComments)processing time:6.416000ms
:2012/8/4 1:53:26[1182992704]:(GetAppComments)processing time:3.321000ms
:2012/8/4 1:53:37[1166182720]:(GetAppComments)processing time:5.821000ms
:2012/8/4 1:53:38[1101044032]:(GetAppComments)processing time:12.046000ms
提取的结果:
2012/8/4 1:53:9 GetAppComments 5.329000
2012/8/4 1:53:9 GetAppComments 4.962000
2012/8/4 1:53:10 GetAppComments 5.840000
...

[解决办法]

Perl code
J:\Project\Perl>perl -nle "@ds = m|^:([^[]+)[^:]+:\(([^)]+)[^:]+:(.*?)ms$|; print qq(@ds);" l5.txt2012/8/4 1:53:9 GetAppComments 5.3290002012/8/4 1:53:9 GetAppComments 4.9620002012/8/4 1:53:10 GetAppComments 5.8400002012/8/4 1:53:11 GetAppComments 5.4410002012/8/4 1:53:11 GetAppComments 5.0310002012/8/4 1:53:17 GetAppComments 5.3540002012/8/4 1:53:25 GetAppComments 6.4160002012/8/4 1:53:26 GetAppComments 3.3210002012/8/4 1:53:37 GetAppComments 5.8210002012/8/4 1:53:38 GetAppComments 12.046000J:\Project\Perl>
[解决办法]
PHP code
[liangdong@bb-browser-test00.vm.baidu.com sh_project]$ ./main.sh   2012/8/4 GetAppComments 5.3290002012/8/4 GetAppComments 4.9620002012/8/4 GetAppComments 5.8400002012/8/4 GetAppComments 5.4410002012/8/4 GetAppComments 5.0310002012/8/4 GetAppComments 5.3540002012/8/4 GetAppComments 6.4160002012/8/4 GetAppComments 3.3210002012/8/4 GetAppComments 5.8210002012/8/4 GetAppComments 12.046000[liangdong@bb-browser-test00.vm.baidu.com sh_project]$ cat main.sh #!/bin/bashwhile read line;do        line=`echo $line | tr "()" " " | cut -c 2- | awk '{gsub("time:|ms", "", $5);print $1" "$3" "$5}'`        echo $linedone < a.txt 

热点排行