Checking for empty lines in a file

Viewed 19134

I don't have a code example here since I'm not sure how to do this at all, but I have a file. A legal empty line is one that only contains the new-line tab. Spaces or tabs are illegal.

How do I check if a line is "legally empty"?

If it doesn't have any words (I can check this with wc -w), how do I check if it has no spaces or tabs either, just new-line?

So I've tried something like this:

while read line; do
    if [[ "$line" =~ ^$ ]]; then
        echo empty line
        continue
    fi
done < $1

But it's not working. If I put a " " in an otherwise empty line, it still considers it empty.

3 Answers
Related