Is there a way to use the head command to find the first line of a file that contains non-whitespace? It would be too kludgy just read the first 100 lines and hope that one of them has non-whitespace.
It doesn't have to be with the head command - all I am looking for is a very performant way to avoid reading the whole file and just getting the first line that matches non-whitespace.
You can do this with simple
grep
and a regular expressionThe
\S+
will match any non-whitespace characters, and with-m 1
we will stop after the first match.