I have a bunch of files, and I'm trying to find the ones that contain the string "EXECUTION FAILED" and also display the previous 10 lines prior to the "EXECUTION FAILED". I am wondering how I can do this?
Asked
Active
Viewed 510 times
1 Answers
1
With :
grep -B10 'EXECUTION FAILED' files*
From
LESS=+/'^ +-B' man grep
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.

Gilles Quénot
- 33,867
man grep
will tell you the answer. – Ed Morton Apr 12 '23 at 16:00