How can I view in less
from the first instance of some arbitrary string "foo" to the last instance?
This arbitrary string will be on most every line of the log. I don't want to do grep "foo" bar.log | less
because it won't be on each line that's relevant.
Let's say the file is
1 Random junk I don't want to see
2 Care about (foo)
3 Care about (foo)
4 Care about
5 Care about (foo)
6 Other random junk I don't want to see
Unfortunately the lines I want to ignore do not follow a nice pattern, otherwise I could use just grep -v 'insert pattern here'
.
I am wondering how to get the following into less
somehow,
2 Care about (foo)
3 Care about (foo)
4 Care about
5 Care about (foo)
grep "foo" bar.log | less
will not work because it ignores line 4, which is one I care about.
sed
beforeless
? – Jeff Schaller Mar 17 '16 at 15:23grep
, one where you only get shown one result at a time and you can switch between them? – phk Mar 17 '16 at 15:28grep
andsed
because they seemed like the tools that would be able to do this. – Captain Man Mar 17 '16 at 15:31pcregrep -M 'foo.*(\n|.)*foo' infile
– don_crissti Mar 17 '16 at 15:32