awk - how to select multiple line in log -


i try make file. has error message in particular log file.

this log contents.

[error] 2015-08-05 14:20:10 handlerexceptionresolver - org.springframework.jdbc.badsqlgrammarexception: ..... ..e(sqlerrorcodesqlexceptiontranslator.java:231) ..ractfallbacksqlexceptiontranslator.java:73) ..possible(mybatisexceptiontranslator.java:73) ..interceptor.invoke(sqlsessiontemplate.java:371) ..electone(unknown source) ..emplate.selectone(sqlsessiontemplate.java:163) [info] 2015-08-05 14:20:39 logginginterceptor -  /products/430 

and try it

awk '$1 ~/^\[error\]$/{print$0}' original.log > extract.log 

but result 1 line.

[error] 2015-08-05 14:20:10 handlerexceptionresolver - 

my expected is..

[error] 2015-08-05 14:20:10 handlerexceptionresolver - org.springframework.jdbc.badsqlgrammarexception: ..... ..e(sqlerrorcodesqlexceptiontranslator.java:231) ..ractfallbacksqlexceptiontranslator.java:73) ..possible(mybatisexceptiontranslator.java:73) ..interceptor.invoke(sqlsessiontemplate.java:371) ..electone(unknown source) ..emplate.selectone(sqlsessiontemplate.java:163) 

i want know how extract error message.

one idea turn printing off , on depending on level want print:

$ cat log.awk /^\[[a-z]+\]/ { flag = 0 } /^\[error\]/ { flag = 1 } flag  $ cat log.txt [error] 2015-08-05 14:20:10 handlerexceptionresolver -enter code here org.springframework.jdbc.badsqlgrammarexception:enter code here .....enter code here ..e(sqlerrorcodesqlexceptiontranslator.java:231)enter code here ..ractfallbacksqlexceptiontranslator.java:73)enter code here ..possible(mybatisexceptiontranslator.java:73)enter code here ..interceptor.invoke(sqlsessiontemplate.java:371)enter code ..electone(unknown source)enter code here ..emplate.selectone(sqlsessiontemplate.java:163)enter code here [info] 2015-08-05 14:20:39 logginginterceptor - /products/430 [error] other multiline error [warn] warning not error  $ awk -f log.awk log.txt [error] 2015-08-05 14:20:10 handlerexceptionresolver -enter code here org.springframework.jdbc.badsqlgrammarexception:enter code here .....enter code here ..e(sqlerrorcodesqlexceptiontranslator.java:231)enter code here ..ractfallbacksqlexceptiontranslator.java:73)enter code here ..possible(mybatisexceptiontranslator.java:73)enter code here ..interceptor.invoke(sqlsessiontemplate.java:371)enter code ..electone(unknown source)enter code here ..emplate.selectone(sqlsessiontemplate.java:163)enter code here [error] other multiline error 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -