Results 1 to 2 of 2
I want some log from a file using grep excluding two patterns
Ex:
$ cat db01_application.log
10:07 AM : Memory sets allocated.
10:12 AM : Log Loading Started.
10.26 AM ...
- 08-23-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 1
Grep between two patterns
I want some log from a file using grep excluding two patterns
Ex:
$ cat db01_application.log
10:07 AM : Memory sets allocated.
10:12 AM : Log Loading Started.
10.26 AM : Table temp1 loaded.
10.56 AM : Table temp2 loaded.
11:23 AM : Log Loaded successfully.
11:25 AM : Link Esablished.
From this file I want activities which are happened between these two patterns Log Loading Started and Log Loaded successfully.
I want following output from this file
10.26 AM : Table temp1 loaded.
10.56 AM : Table temp2 loaded.
Could some one please let me know any idea how to retrieve this particular block from this file
Thanks
- 08-23-2007 #2
gawk to the rescue. Here is one way to do it:
Great reference here: The GNU Awk User's GuideCode:[bevo@four ~]$ cat some-logfile 10:07 AM : Memory sets allocated. 10:12 AM : Log Loading Started. 10.26 AM : Table temp1 loaded. 10.56 AM : Table temp2 loaded. 11:23 AM : Log Loaded successfully. 11:25 AM : Link Esablished. [bevo@four ~]$ gawk ' { if ($0 ~ /Log Loaded successfully/) exit ; if ( printit == "true" ) print ; if ($0 ~ /Log Loading Started/) printit = "true" } ' some-logfile 10.26 AM : Table temp1 loaded. 10.56 AM : Table temp2 loaded.


Reply With Quote
