I’m not even sure if this is possible using grep or if any other tools is needed. I’ll explain what I want to do.
If I have a file foo.txt like the following:
a
b
c
d
e
When doing grep c foo.txt I want the result to be something like this:
b
c
d
Being the result and its surroundings.
Is this possible? Which is the option to be used?
Use
-C(context) flag of grep. Similar flags are-A(after) and-B(before). The argument is the number of lines in the context.