Reputation: 33
I have following log:
File Process Start : 2014-03-12 - 10:43:40 UnZipping File : fetch_export?id=t63184&file=4 Extracted File : exp_4.mbx Expected Messages : 6236 File Process Start : 2014-03-12 - 10:57:38 UnZipping File : fetch_export?id=t63185&file=39 Extracted File : Expected Messages : 0 File Process Start : 2014-03-12 - 10:57:38 UnZipping File : fetch_export?id=t63185&file=33 Extracted File : Expected Messages : 0 File Process Start : 2014-03-12 - 10:57:38 UnZipping File : fetch_export?id=sept2012&file=61 Extracted File : exp_61.mbx Expected Messages : 7935
What i need to change in this command?
sed -n '/File Process Start/,/Expected Messages/p'
I need output only between
File Process Start ... Expected Messages : 0
Like this:
File Process Start : 2014-03-12 - 10:57:38 UnZipping File : fetch_export?id=t63185&file=39 Extracted File : Expected Messages : 0 File Process Start : 2014-03-12 - 10:57:38 UnZipping File : fetch_export?id=t63185&file=33 Extracted File : Expected Messages : 0
Upvotes: 3
Views: 75
Reputation: 58420
This might work for you (GNU sed):
sed -n '/File Process Start/{h;d};H;/Expected Messages : 0/{g;p}' file
Upvotes: 0
Reputation: 1159
The idea is to print the lines between "File Process Start..." and "Expected Messages : 0". The issue is that you don't know beforehand if you will find the "Expected Messages : 0" or "Expected Messages : X". So, starting at the "File Process Start", keep saving the lines in the hold space until you are able to decide if you will print them or discard them.
sed -n '/Expected Messages : 0/{H;g;p};/.*/H;/File Process Start/h' log.txt
The pseudocode is:
If the line contains "Expected Messages : 0", (h) append this line in the hold space (at this point, the hold space will have the lines "File Process Start ...", "UnZipping File..." and "Extracted File..."), (g) get the content from the hold space to the pattern space (i.e. the lines from "File Process Start..." until the last one you just appended), (p) print the content of the pattern space.
If the line contains anything else, (H) append it to the hold space.
If the line contains "File Process Start", (h) wipe out what's in the hold space and put this new line there.
Upvotes: 2