Delete empty lines from a file - Unix

This is a discussion on Delete empty lines from a file - Unix ; Hello all,
I need to delete empty lines from a file (with spaces only - not null
records).
The following command works only for null rows, but not in case of
spaces:
sed '/^$/d' filename
thanks in advance!
Shulamit...

Delete empty lines from a file

I need to delete empty lines from a file (with spaces only - not null
records).
The following command works only for null rows, but not in case of
spaces:
sed '/^$/d' filename

thanks in advance!
Shulamit

Re: Delete empty lines from a file

On Tue, 06 Nov 2007 02:36:46 -0800, shulamitm wrote:
> Hello all,
> I need to delete empty lines from a file (with spaces only - not null
> records).
>
> The following command works only for null rows, but not in case of
> spaces:
>
> sed '/^$/d' filename

If you are not interested in preserving literal TAB characters, you can
use something like this:

expand filename | sed -e 's/^[ ]*$//'

Handling TABs is probably easier to type in Perl:

perl -ne 'print if (!m/^[ \t]*$/);'

Re: Delete empty lines from a file

In <1194345406.931898.200050@y42g2000hsy.googlegroups. com> shulamitm writes:
> I need to delete empty lines from a file (with spaces only - not null
> records).

sed '/^ *$/d' filename

--
John Gordon A is for Amy, who fell down the stairsgordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Re: Delete empty lines from a file

On Nov 6, 2:36 am, shulamitm wrote:
> Hello all,
>
> I need to delete empty lines from a file (with spaces only - not null
> records).
> The following command works only for null rows, but not in case of
> spaces:
> sed '/^$/d' filename

grep '[^ ]*' filename

Re: Delete empty lines from a file

Hi ,
u can use grep command to delete blank lien from a file , which is :

grep -v '^$' filenaem > new_filename

command will delete blank lines and saved teh new contents in new_filename , and if u want again u can copy teh new_filename contents to teh previous file..which is now without blank lines.