Linux sed and awk Cheat Sheet/Print only matching lines

Use sed as a pattern filter.

Section: sed Line Deletion and Printing

Print only matching lines

bash
bash
sed -n '/ERROR/p' app.log
Explanation

Suppress default output with `-n`, then explicitly print matches.

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 sed Line Deletion and Printing
Print a line range only
Show lines 5 through 10.
OpenIn sheetbashsame section
Delete blank lines
Remove empty lines from output.
OpenIn sheetbashsame section
Delete comment lines
Skip lines that begin with `#`.
OpenIn sheetbashsame section
Delete a line range
Remove lines 5 through 10.
OpenIn sheetbashsame section
Replace first occurrence per line
Substitute one match in each line.
OpenIn sheetbash1 tag match
Print rows matching a condition
Show lines where column 3 is greater than 100.
OpenIn sheetbash1 tag match