Show lines containing at least one non-space character.

Section: Regex with grep

Find non-blank lines

bash
bash
grep -n '[^[:space:]]' file.txt
Explanation

Useful when skipping whitespace-only 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 Regex with grep
Use extended regex
Enable `+`, `?`, and alternation without heavy escaping.
OpenIn sheetbashsame section
Match literal text only
Disable regex interpretation.
OpenIn sheetbashsame section
Match line start and end
Search with anchors.
OpenIn sheetbashsame section
Find blank lines
Search for empty lines.
OpenIn sheetbashsame section
Search for a word
Print lines containing a pattern.
OpenIn sheetbash1 tag match
Search recursively
Search all files under a directory.
OpenIn sheetbash1 tag match