sed and grep

I am stranded with a problem. Please solve.

How will you remove blank lines from a file using sed and grep? ( blank line contains nothing or only white spaces).

I run the below commands of sed and grep but grep isn't giving output as desired. Why?

sed '/^[ \o11]*$/d' blank

grep -v "^[ \o11]*$" blank

(there is a space before tab in character class)

The above sed command gave desired result but not grep. Why?

Also, I am fix at one more place. As, tab is 011 (octal) but in my system the zero of 011 is accepting as o (alphabetic) instead of numeral zero. If I give numeral zero, it won't work. Is it O.K.? A few days back by mistake a system file got deleted becz of which link count is not showing properly. Can this be a reason for the above problem.

Waiting eagerly for your valuable replies.

I suppose it is because of the way you quote. You should probably single-quote the grep-expression as well as you did with the sed-expression.

You don't need either representation of tabs, as you can enter them directly when you use single-quotes to protect these characters (replace "<spc>" and "<tab>" with literal spaces/tabs when enering the following):

sed '/^[<spc><tab>]*$/d' blank

I hope this helps.

bakunin

blank lines and whitespaces lines could be removed using this regex:

sed '/^ *$/d'

I find it hard to believe that either of these commands did what you want. The \o11 needs to be \011 (i.e., digit zero; not lowercase letter oh).

To make it clearer to readers, you could also replace your bracket expression with [[:space:]].