I tried grep -v \'^$\'
in Linux and that didn\'t work. This file came from a Windows file system.
I tried hard, but this seems to work (assuming \r
is biting you here):
printf "\r" | egrep -xv "[[:space:]]*"
Use:
grep pattern filename.txt | uniq
It's true that the use of grep -v -e '^$' can work, however it does not remove blank lines that have 1 or more spaces in them. I found the easiest and simplest answer for removing blank lines is the use of awk. The following is a modified a bit from the awk guys above:
awk 'NF' foo.txt
But since this question is for using grep I'm going to answer the following:
grep -v '^ *$' foo.txt
Note: the blank space between the ^ and *.
Or you can use the \s to represent blank space like this:
grep -v '^\s*$' foo.txt