免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2056 | 回复: 7
打印 上一主题 下一主题

求助 文件字符串查找 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-29 12:44 |只看该作者 |倒序浏览
有一文件内容如下:(Text开头的都是一行)结果最好能按照  Elapsed Execution Time的后面的时间大小排列
Text     : CALL SYSIBM.SQLTABLES(?,?,?,?,?)
  Internal rows deleted: 0
  Internal rows updated: 0
  Internal rows inserted: 0
  Bufferpool data logical reads: 0
  Bufferpool data physical reads: 0
  Bufferpool temporary data logical reads: 0
  Bufferpool temporary data physical reads: 0
  Bufferpool index logical reads: 0
  Bufferpool index physical reads: 0
  Elapsed Execution Time:  0.000012 seconds

  Text     : SELECT CAST( NULL AS VARCHAR(12 ) AS TABLE_CAT, RTRIM(T.CREATOR) AS TABLE_SCHEM, T.NAME AS TABLE_NAME, CASE WHEN T.TYPE='T' AND T.CREATOR='SYSIBM' THEN 'SYSTEM TABLE' WHEN T.TYPE='T' AND T.CREATOR<>'SYSIBM' THEN 'TABLE' WHEN T.TYPE='V' AND T.STATUS<>'X' THEN 'VIEW' WHEN T.TYPE='V' AND T.STATUS='X' THEN 'INOPERATIVE VIEW' WHEN T.TYPE='X' THEN NULL WHEN T.TYPE='N' THEN 'SYNONYM' ELSE TT.TABLE_TYPE END AS TABLE_TYPE, T.REMARKS FROM SYSIBM.SYSTABLES T, SYSIBM.SQLTABLETYPES TT WHERE T.TYPE = TT.TYPE AND T.CREATOR = 'PBCATOWN' AND T.NAME = 'pbcattbl' ORDER BY 4,1,2,3
Internal rows deleted: 0
  Internal rows updated: 0
  Internal rows inserted: 0
  Bufferpool data logical reads: 0
  Bufferpool data physical reads: 0
  Bufferpool temporary data logical reads: 0
  Bufferpool temporary data physical reads: 0
  Bufferpool index logical reads: 0
  Bufferpool index physical reads: 0
  Elapsed Execution Time:  0.000232 seconds

Text     : SELECT CAST( NULL AS VARCHAR(12 ) AS TABLE_CAT, RTRIM(T.CREATOR) AS TABLE_SCHEM, T.NAME AS TABLE_NAME, CASE WHEN T.TYPE='T' AND T.CREATOR='SYSIBM' THEN 'SYSTEM TABLE' WHEN T.TYPE='T' AND T.CREATOR<>'SYSIBM' THEN 'TABLE' WHEN T.TYPE='V' AND T.STATUS<>'X' THEN 'VIEW' WHEN T.TYPE='V' AND T.STATUS='X' THEN 'INOPERATIVE VIEW' WHEN T.TYPE='X' THEN NULL WHEN T.TYPE='N' THEN 'SYNONYM' ELSE TT.TABLE_TYPE END AS TABLE_TYPE, T.REMARKS FROM SYSIBM.SYSTABLES T, SYSIBM.SQLTABLETYPES TT WHERE T.TYPE = TT.TYPE AND T.CREATOR = 'PBCATOWN' AND T.NAME = 'pbcattbl' ORDER BY 4,1,2,3
Internal rows deleted: 0
  Internal rows updated: 0
  Internal rows inserted: 0
  Bufferpool data logical reads: 0
  Bufferpool data physical reads: 0
  Bufferpool temporary data logical reads: 0
  Bufferpool temporary data physical reads: 0
  Bufferpool index logical reads: 0
  Bufferpool index physical reads: 0
  Elapsed Execution Time:  0.000422 seconds


RESULT:

Text     : CALL SYSIBM.SQLTABLES(?,?,?,?,?)
Elapsed Execution Time:  0.000012 seconds
Text     : SELECT CAST( NULL AS VARCHAR(12 ) AS TABLE_CAT, RTRIM(T.CREATOR) AS TABLE_SCHEM, T.NAME AS TABLE_NAME, CASE WHEN T.TYPE='T' AND T.CREATOR='SYSIBM' THEN 'SYSTEM TABLE' WHEN T.TYPE='T' AND T.CREATOR<>'SYSIBM' THEN 'TABLE' WHEN T.TYPE='V' AND T.STATUS<>'X' THEN 'VIEW' WHEN T.TYPE='V' AND T.STATUS='X' THEN 'INOPERATIVE VIEW' WHEN T.TYPE='X' THEN NULL WHEN T.TYPE='N' THEN 'SYNONYM' ELSE TT.TABLE_TYPE END AS TABLE_TYPE, T.REMARKS FROM SYSIBM.SYSTABLES T, SYSIBM.SQLTABLETYPES TT WHERE T.TYPE = TT.TYPE AND T.CREATOR = 'PBCATOWN' AND T.NAME = 'pbcattbl' ORDER BY 4,1,2,3
Elapsed Execution Time:  0.000232 seconds
Text     : SELECT CAST( NULL AS VARCHAR(12 ) AS TABLE_CAT, RTRIM(T.CREATOR) AS TABLE_SCHEM, T.NAME AS TABLE_NAME, CASE WHEN T.TYPE='T' AND T.CREATOR='SYSIBM' THEN 'SYSTEM TABLE' WHEN T.TYPE='T' AND T.CREATOR<>'SYSIBM' THEN 'TABLE' WHEN T.TYPE='V' AND T.STATUS<>'X' THEN 'VIEW' WHEN T.TYPE='V' AND T.STATUS='X' THEN 'INOPERATIVE VIEW' WHEN T.TYPE='X' THEN NULL WHEN T.TYPE='N' THEN 'SYNONYM' ELSE TT.TABLE_TYPE END AS TABLE_TYPE, T.REMARKS FROM SYSIBM.SYSTABLES T, SYSIBM.SQLTABLETYPES TT WHERE T.TYPE = TT.TYPE AND T.CREATOR = 'PBCATOWN' AND T.NAME = 'pbcattbl' ORDER BY 4,1,2,3
Elapsed Execution Time:  0.000422 seconds

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
2 [报告]
发表于 2009-12-29 12:51 |只看该作者
要干吗啊?

论坛徽章:
0
3 [报告]
发表于 2009-12-29 13:00 |只看该作者
text内容执行时间长短

论坛徽章:
0
4 [报告]
发表于 2009-12-29 13:40 |只看该作者
我帮你-v-


  1. #!/usr/bin/env ruby -w

  2. hash = {}

  3. File.open("whatever").each("Text") do |line|
  4.   value1 = String.new
  5.   key = String.new
  6.   value2 = String.new
  7.   value1 = "Text    #{$&}" if line =~ /\:.*?\n/
  8.   key, value2 = $1, $& if line =~ /Elapsed.*?(\d+).*/
  9.   (hash[value1] ||= [])  << (value1 + value2)
  10. end


  11. hash.keys.sort.each do |key|
  12.   puts hash[key]
  13. end
复制代码

论坛徽章:
0
5 [报告]
发表于 2009-12-29 13:47 |只看该作者

回复 #1 lifeexpert 的帖子

你要是高圆圆就好了。

论坛徽章:
0
6 [报告]
发表于 2009-12-29 13:59 |只看该作者

回复 #4 cxfcxf 的帖子

谢了 ,我是用liunx shell,不好用,执行不了

论坛徽章:
0
7 [报告]
发表于 2009-12-29 14:00 |只看该作者
装个ruby好莱 要么我帮你翻译成perl....-_-

论坛徽章:
0
8 [报告]
发表于 2009-12-29 14:48 |只看该作者

  1. #!/usr/bin/perl

  2. my %hash;
  3. $/ = "Text";

  4. while (<>) {
  5.         chomp;
  6.         my $value1 = "Text    $&" if /\:.*?\n/;
  7.         my ($key, $value2) = ($1, $&) if /Elapsed.*?(\d+).*/;
  8.         push @{$hash{$key}}, "${value1}${value2}\n\n";
  9. }

  10. foreach (sort {$a <=> $b} keys %hash) {
  11.         print "@{$hash{$_}}\n";
  12. }
复制代码


写好文件 然后执行 ./script filename
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP