So I have a log that contains something like this:
What I want is to get the first occurrence of "^localhost0" (at line start) and then everything else up to the last occurrence of "^localhost0" (at line start)
Ideally I don't even care about the 2 "localhost0" lines either. All I really care about is the information stored between the command and the exit call.
I cannot seem to think of a way to do this with grep... aka
I can think of two approaches:
Store the data to display in memory while you figure out what is 'in' and what's 'out'.
Run through the file a couple of times.
As I don't know how big the file is, we'll go with the multiple passes solution - it's ugly but it has a predictable memory footprint