Linux grep and ripgrep Cheat Sheet/Show lines after a match

Print 5 lines after each match.

Section: Context Around Matches

Show lines after a match

bash
bash
grep -A 5 ERROR app.log
Explanation

After-context often shows stack traces or follow-up log lines.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Context Around Matches
Show lines before a match
Print 3 lines before each match.
OpenIn sheetbashsame section
Show lines before and after
Print context on both sides of a match.
OpenIn sheetbashsame section
Search for a word
Print lines containing a pattern.
OpenIn sheetbash1 tag match
Use extended regex
Enable `+`, `?`, and alternation without heavy escaping.
OpenIn sheetbash1 tag match
Search recursively
Search all files under a directory.
OpenIn sheetbash1 tag match
Case-insensitive search
Match regardless of uppercase or lowercase.
OpenIn sheetbash1 tag match