Delete empty lines from a file

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!
shulamitm [ Di, 06 November 2007 12:11 ] [ ID #1863293 ]

Re: Delete empty lines from a file

2007-11-06, 03:11(-08), shulamitm:
> 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 '[^[:blank:]]' filename

awk NF filename

--
Stéphane
Stephane CHAZELAS [ Di, 06 November 2007 12:18 ] [ ID #1863294 ]

Re: Delete empty lines from a file

shulamitm wrote:
>
> 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

[GNU sed & grep]

sed '/^ \+$/d' filename

or

grep -v '^ \+$' filename

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Cyrus Kriticos [ Di, 06 November 2007 12:35 ] [ ID #1863295 ]

Re: Delete empty lines from a file

On Nov 6, 1:18 pm, Stephane CHAZELAS <this.addr... [at] is.invalid> wrote:
> 2007-11-06, 03:11(-08), shulamitm:> I need to delete empty lines from a f=
ile (with spaces only - not null
> > records). The following command works only for null rows, but not in
> > case of spaces: sed '/^$/d' filename
>
> [...]
>
> grep '[^[:blank:]]' filename
>
> awk NF filename
>
> --
> St=E9phane

thanks!
shulamitm [ Di, 06 November 2007 12:39 ] [ ID #1863297 ]
Linux » comp.unix.shell » Delete empty lines from a file

Vorheriges Thema: Alternative to ksh/whence
Nächstes Thema: Article Directory script