ファイル内のパターンを見つけ、パターンが見つかった場合に印刷する方法は?

ファイル内のパターンを見つけ、パターンが見つかった場合に印刷する方法は?

はい -

テストログ:

ConductID: null; RunOpSequenceCode: 12345678; ClientID: null; FescoOfferID: null; PriorityCode: null; RowNumberStart: 0; FetchSize: 0; ChannelTypes: ER,PART; NigoIndicator: null; TreatmentTypeCode: null; DivisionName: null; DivisionCode: null; }
[11-21-2099 23:25:28] [OK #6:DAMN_BATCH ] T123Util             setT123Columns 
ConductID: null; RunOpSequenceCode: 12345678; ClientID: null; FescoOfferID: null; PriorityCode: null; RowNumberStart: 0; FetchSize: 0; ChannelTypes: ER,PART; NigoIndicator: null; TreatmentTypeCode: null; DivisionName: null; DivisionCode: null; }
[11-21-2099 23:25:28] [OK #6:DAMN_BATCH ] T123Util             setT123Columns 
ConductID: null; RunOpSequenceCode: 12345678; ClientID: null; FescoOfferID: null; PriorityCode: null; RowNumberStart: 0; FetchSize: 0; ChannelTypes: ER,PART; NigoIndicator: null; TreatmentTypeCode: null; DivisionName: null; DivisionCode: null; }
[11-21-2099 23:25:28] [OK #6:DAMN_BATCH ] T123Util             setT123Columns       WARN : UserDefined Tatty Error: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [72000]; error code [20001];
--- The error occurred in com//tmo/asfjn/jdaf/tkenjrt/terkj.xml
--- The error occurred while eating sandwich.
--- Check the tim-tim-nothing-boy.
--- Cause: java.sql.SQLException: ORA-00001: You suck.
ORA-06512: at "test_amp_tim.pkg", line 78

今度は、スクリプトで「UserDefined Tatty Error」を見つけて、「An error発生...」から「You're too bad」まで印刷したいと思います。

私はgrep -Fxqとsedを試しましたが、成功しませんでした。ありがとうございます。

ベストアンサー1

このような?

awk '# If we see the error, set t to 1
    /UserDefined Tatty Error/ { t=1; next }
    # If it's not a --- reset t to 0 (even if it's already 0)
    !/^--- / { t=0 }
    # If t==1 we are inside the error message; so, print
    t' file

おすすめ記事