unable to filter out blank lines ^$ matches nothing

Hi
I've got a file with a lot of blank lines in it or are they?...I tried to remove them by using

grep -v ^$ <filename>

This did not remove anything....I then tried the reverse to see if ^$ indeed matches anything...so I tried

$ grep ^$ grepres.txt
$ grep ^\s*$ grepres.txt

This matched nothing...

..I am a bit of a noob at this so if anyone out there can figure out how to do this using regular expressions...I would really appreciate it...

I've attached the file here

Thanks in advance...

To remove blank lines using sed:

sed '/^$/d' infile > outfile

If u want to use grep then...

grep . grepres.txt

Hi.

My experience has been that I have often received files that contain spaces and TABS in otherwise empty lines. I call these visually empty lines. Usually we want to get rid of these as well as lines which have no characters at all.

Here is what I usually use:

#!/usr/bin/env sh

# @(#) dbl      Delete blank ( visually empty ) lines.
# If POSIX character class does not work, then use
# [ SPACE TAB ].

grep -v '^[[:space:]]*$' $*
# grep -v '^[   ]*$' $*

exit $?

Here is a demonstration script:

#!/bin/bash -

# @(#) s1       Demonstrate visually empty line processing.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) cat grep

FILE=${1-data1}

echo
echo " Input file $FILE:"
cat -A $FILE

echo
echo " Processed with grep '.':"
grep . $FILE

echo
echo " Processing with dbl:"
./dbl $FILE

exit 0

Which produces:

% ./s1
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
cat (coreutils) 5.2.1
grep (GNU grep) 2.5.1

 Input file data1:
First line.$
Next line has no characters.$
$
Next line has 1 space.$
 $
Next line has 1 TAB.$
^I$
Penultimate line.$
Last line.$

 Processed with grep '.':
First line.
Next line has no characters.
Next line has 1 space.

Next line has 1 TAB.

Penultimate line.
Last line.

 Processing with dbl:
First line.
Next line has no characters.
Next line has 1 space.
Next line has 1 TAB.
Penultimate line.
Last line.

Best wishes ... cheers, drl

Hi

..sorry didnt mention in my first post that sed '/^$/d' didnt work...

...grep . filename selects everything dosent it..?

....grep -v '^[[:space:]]*$' worked perfectly..

thing is there was a space in the line...dunno why \s*$ didnt work....

thanks a lot drl...

This file contain no empty lines. You got some whitespaces in there.