Issue
I want a way to search in a given text. For that, I use grep
:
grep -i "my_regex"
That works. But given the data like this:
This is the test data
This is the error data as follows
. . .
. . . .
. . . . . .
. . . . . . . . .
Error data ends
Once I found the word error
(using grep -i error data
), I wish to find the 10 lines that follow the word error
. So my output should be:
. . .
. . . .
. . . . . .
. . . . . . . . .
Error data ends
Are there any way to do it?
Solution
You can use the -B
and -A
to print lines before and after the match.
grep -i -B 10 'error' data
Will print the 10 lines before the match, including the matching line itself.
Answered By - Jon Lin Answer Checked By - David Goodson (WPSolving Volunteer)