日期:2014-05-16  浏览次数:20724 次

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.txt
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
2012/8/4 1:53:11 GetAppComments 5.441000
2012/8/4 1:53:11 GetAppComments 5.031000
2012/8/4 1:53:17 GetAppComments 5.354000
2012/8/4 1:53:25 GetAppComments 6.416000
2012/8/4 1:53:26 GetAppComments 3.321000
2012/8/4 1:53:37 GetAppComments 5.821000
2012/8/4 1:53:38 GetAppComments 12.046000

J:\Project\Perl>

------解决方案--------------------
PHP code
[liangdong@bb-browser-test00.vm.baidu.com sh_project]$ ./main.sh   
2012/8/4 GetAppComments 5.329000
2012/8/4 GetAppComments 4.962000
2012/8/4 GetAppComments 5.840000
2012/8/4 GetAppComments 5.441000
2012/8/4 GetAppComments 5.031000
2012/8/4 GetAppComments 5.354000
2012/8/4 GetAppComments 6.416000
2012/8/4 GetAppComments 3.321000
2012/8/4 GetAppComments 5.821000
2012/8/4 GetAppComments 12.046000
[liangdong@bb-browser-test00.vm.baidu.com sh_project]$ cat main.sh 
#!/bin/bash

while read line;do
        line=`echo $line | tr "()" " " | cut -c 2- | awk '{gsub("time:|ms", "", $5);print $1" "$3" "$5}'`
        echo $line
done < a.txt