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?
You can use the
-Band-Ato print lines before and after the match.Will print the 10 lines before the match, including the matching line itself.