免费注册 查看新帖 |

Chinaunix

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

帮忙分析下这个日志,抽取其中的SQL语句 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-30 20:12 |只看该作者 |倒序浏览
我想把红色标示的SQL抽取出来,也有update语句delete语句。 SQL语句也有换行的情况,抽取之后,SQL语句必须由多行变为一行。


LOG:  statement: SELECT c.relname FROM sys_catalog.sys_namespace u, sys_catalog.sys_class c WHERE u.oid = c.relnamespace AND u.nspname = UPPER('PUBLIC') AND c.relname = UPPER('KDB_BIGINT')
LOG:  statement: INSERT INTO TEST.PUBLIC.KDB_BIGINT (KDB_ID, KDB_BIGINT1) VALUES (8, 9223372036854775807)
LOG:  statement: INSERT INTO TEST.PUBLIC.KDB_BIGINT (KDB_ID, KDB_BIGINT1) VALUES (9, 12345)
LOG:  statement: INSERT INTO TEST.PUBLIC.KDB_BIGINT (KDB_ID, KDB_BIGINT1) VALUES (10, -922337203685477580
LOG:  statement: ROLLBACK
LOG:  close _PLAN0EE4CFC0
LOG:  statement:  
LOG:  statement: set DateStyle to 'ISO'
LOG:  statement: show implicit_savepoint
LOG:  statement: show server_encoding
LOG:  statement: set client_encoding to 'GBK'
LOG:  statement: show case_sensitive
LOG:  statement: SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED
LOG:  statement: BEGIN
LOG:  statement: select * from KDB_BIGINT_IDENTITY order by  KDB_ID
LOG:  statement: ROLLBACK
LOG:  statement: set client_encoding to 'GBK'
LOG:  statement: select * from
        KDB_FLOAT
        where KDB_ID =1;

LOG:  statement: select * from
        TEST_MERGE_INTO_DEST;

LOG:  statement: set client_encoding to 'GBK'
NOTICE:  CheckPoint Start at: 2011-03-30 14:08:01
NOTICE:  CheckPoint Sync Start at: 2011-03-30 14:08:03
NOTICE:  CheckPoint Done at: 2011-03-30 14:08:03
ERROR:  syntax error at or near "." at character 18
STATEMENT:  select a.KDB_ID a.KDB_INT1
        from KDB_INT a, KDB_FLOAT b
        where a.KDB_ID=b.KDB_ID;
LOG:  statement: select a.KDB_ID,a.KDB_INT1
        from KDB_INT a, KDB_FLOAT b
        where a.KDB_ID=b.KDB_ID;

FATAL:  terminating connection due to administrator command
LOG:  received fast shutdown request
LOG:  aborting any active transactions
LOG:  shutting down

论坛徽章:
0
2 [报告]
发表于 2011-03-30 21:38 |只看该作者
  1. [root@fc9 shell]# sed -r  -n  '/statement:\s*select/{:a;/statement:.*(LOG|FATAL)/!{N;ba};s/.*: (.*)(LOG|FATAL).*/\1/;s/\n/ /g;s/\s+/ /g;p}' d
  2. select * from KDB_BIGINT_IDENTITY order by KDB_ID
  3. select * from KDB_FLOAT where KDB_ID =1;
  4. select a.KDB_ID,a.KDB_INT1 from KDB_INT a, KDB_FLOAT b where a.KDB_ID=b.KDB_ID;
  5. [root@fc9 shell]#
复制代码

论坛徽章:
0
3 [报告]
发表于 2011-03-30 22:02 |只看该作者
金牙哥好猛

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
4 [报告]
发表于 2011-03-30 23:05 |只看该作者
本帖最后由 yinyuemi 于 2011-03-31 11:26 编辑

awk:
  1. awk -vRS="LOG:  statement|FATAL" '/: select/{print gensub(/\n| +|:/," ","g",$0)}'  file  
  2.   select * from KDB_BIGINT_IDENTITY order by KDB_ID
  3.   select * from   KDB_FLOAT  where KDB_ID =1;
  4.   select * from   TEST_MERGE_INTO_DEST;
  5.   select a.KDB_ID,a.KDB_INT1  from KDB_INT a, KDB_FLOAT b  where a.KDB_ID=b.KDB_ID;
复制代码

论坛徽章:
0
5 [报告]
发表于 2011-03-31 00:04 |只看该作者
看了半天愣是没怎么明白,sed里“{:"这个是做什么用的?

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
6 [报告]
发表于 2011-03-31 00:13 |只看该作者
回复 5# doujikai


    应该分开看
"{" 和 ":a"

论坛徽章:
0
7 [报告]
发表于 2011-03-31 10:28 |只看该作者
还是不明白,楼上的能推荐一些sed的资料不,我研究下,呵呵

论坛徽章:
0
8 [报告]
发表于 2011-03-31 10:50 |只看该作者
:a在sed里代表什么意思?

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
9 [报告]
发表于 2011-03-31 11:01 |只看该作者

论坛徽章:
0
10 [报告]
发表于 2011-03-31 11:15 |只看该作者
本帖最后由 doujikai 于 2011-03-31 11:17 编辑

终于看懂了,:a应该是做个标记,ba是循环直到/statement:.*(LOG|FATAL)/为止,然后再把换行去掉,把空格换成一个空格,应该就成了,果然很牛!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP