I am trying to read lines from a file containing multiple lines. I want to identify lines containing only spaces. By definition, an empty string is empty and contains nothing (including spaces). I want to detect lines that seem empty but they are not (lines containing only spaces)
while read line; do
if [[ `echo "$line" | wc -w` == 0 && `echo "$line" | wc -c` > 1 ]];
then
echo "Fake empty line detected"
fi
done < "$1"
But since reading ignores spaces at the beginning and end of the line, my code does not work.
file example
hi
hi
(empty line, no spaces or any other char)
hi
(two spaces)
hey
Please help me fix the code
source
share