Search This Blog

grep: include lines before and after the matching line

Include 2 lines before the matching line:
grep -B 2 'keyword' file1



Include 2 more lines after the matching line:
grep -A 2 'keyword' file1

No comments:

Post a Comment