2016-07-31 6 views
-1

db2diag.logからエラー・メッセージを抽出するスクリプトがあります。私は下のファイルからデッドロックを引き起こしたSQLクエリを抽出する必要があります。db2エラー・ログからSQL部分の下にgrepする方法

ファイルの内容:log.txt

db2inst1 , WSCOMUSR , MESSAGE : ADM5501I DB2 is performing lock escalation. The affected application 
      is named "db2jcc_application", and is associated with the workload 
      name "SYSDEFAULTUSERWORKLOAD" and application ID 
      "173.10.105.33.59586.13011817552" at member "0". The total number of 
      locks currently held is "1249935", and the target number of locks to 
      hold is "624967". The current statement being executed is "delete 
      from DMEXPLOG where CREATED < ? ". Reason code "1" 


db2inst1 , WSCOMUSR , MESSAGE : ADM5501I DB2 is performing lock escalation. The affected application 
      is named "db2jcc_application", and is associated with the workload 
      name "SYSDEFAULTUSERWORKLOAD" and application ID 
      "173.10.105.33.59586.13011817552" at member "0". The total number of 
      locks currently held is "1249935", and the target number of locks to 
      hold is "624967". The current statement being executed is "select 
      * from DMEXPLOG where CREATED < ?". Reason code "1" 

必要な出力:すべてのSQLはこのような

1. delete 
      from DMEXPLOG where CREATED < ? 
2. select 
      * from DMEXPLOG where CREATED < ? 

を照会します。ファイルからすべてのSQLパーツが必要です。任意のgrepまたはAwk/sed解決策を得るには?

プラットフォーム:UNIX(AIX)

+2

で翻訳することができ、[編集ヘルプ]をご覧ください(http://stackoverflow.com/editing-助けて)。 – Cyrus

答えて

0
awk '{gsub(/^.*The current statement being executed is \"|\". Reason code.*$/,""); print NR". "$0}' log.txt 
1. delete from DMEXPLOG where CREATED < ? 
2. 
3. select * from DMEXPLOG where CREATED < ? 

一致する文字列は、間違いなく短くすることができますし、あなたが提示されたデータが実際のデータとの間に空行を持っていたので、2は空です。実際のデータに空白行がありますか?

0

たぶん、このヘルプあなた

[email protected]:/tmp$ sed -n '/select/,/^$/p;/delete/,/^$/p;/insert/,/^$/p;/update/,/^$/p' log.txt | sed -n '/^[0-9]/!H;//x;$x;s/\n\([^A]\)/ \1/gp' | awk -F'"' '{printf("%d.\t %s\n", NR, $4)}' 
1. delete    from DMEXPLOG where CREATED < ? 
2. select   * from DMEXPLOG where CREATED < ? 
0

あなたの現在の例では、

sed -n '/statement being executed/ s/.*"//p; /Reason code/ s/".*//p' log 
関連する問題