Posts tonen met het label sed. Alle posts tonen
Posts tonen met het label sed. Alle posts tonen

woensdag 26 september 2012

Bash search logfiles

Bash search logfiles

LogFile example
2012-09-16 19:06:33,450 ERROR [-59] JDBCException ORA-00001: unique constraint (X_UK1) violated
2012-09-16 19:31:39,319 ERROR [-60] JDBCException ORA-00060: deadlock detected (X_UK3) violated
2012-09-16 19:31:39,998 ERROR [-61] JDBCException ORA-00001: unique constraint (X_UK1) violated
2012-09-16 19:41:31,331 ERROR [-62] JDBCException ORA-00001: unique constraint (X_UK2) violated
First option is to grep the lines with ORA-00060:
$ grep ORA-00060 l.log 
2012-09-16 19:31:39,319 ERROR [-60] JDBCException ORA-00060: deadlock detected (X_UK3) violated
Find ORA error strip first part of the line.
$ grep ORA l.log | sed 's/.*ORA/ORA/g' 
ORA-00001: unique constraint (X_UK1) violated
ORA-00060: deadlock detected (X_UK3) violated
ORA-00001: unique constraint (X_UK1) violated
ORA-00001: unique constraint (X_UK2) violated
Search for ORA and count the time they occur.
$ grep ORA l.log | sed 's/.*ORA/ORA/g' | sort | uniq -c
   2 ORA-00001: unique constraint (X_UK1) violated
   1 ORA-00001: unique constraint (X_UK2) violated
   1 ORA-00060: deadlock detected (X_UK3) violated
Search with sed between two dates.
$ sed -n '/^2012-09-16 19:31/p; /^2012-09-16 19:32/q' l.log 
2012-09-16 19:31:39,319 ERROR [-60] JDBCException ORA-00060: deadlock detected (X_UK3) violated
2012-09-16 19:31:39,998 ERROR [-61] JDBCException ORA-00001: unique constraint (X_UK1) violated

dinsdag 25 september 2012

String manipulation with sed

String manipulation with sed

First example

$ echo "Hello world" | sed 's/o/i/g'
Helli wirld

Example with other seperator

$ echo "Hello world"  |sed "s@o@i@g"
Helli wirld

Example with slash forward

$ echo "Hello/ world"  |sed "s@/@.@g"
Hello. world

Example with slash backwards

$ echo "Hello\ world"  |sed "s@\@.@g"
sed: 1: "s@\@.@g": unterminated substitute in regular expression
$ echo "Hello\ world"  |sed "s@\\@.@g"
sed: 1: "s@\@.@g": unterminated substitute in regular expression
$ echo "Hello\ world"  |sed "s@m@.@g"
Hello\ world
$ echo "Hello\ world"  |sed "s@\\\@.@g"
Hello. world