in reply to Re: replacing blank lines
in thread replacing blank lines

$entire_file =~ s/^\n$//mg;

That should leave $entire_file with only nonblank lines

This is assuming that blank lines are TRUELY blank (no spaces). This is more general:

perl -pi -e 's!^\s+?$!!' file.txt or s!^(\n|\s+)$!!g

Cheers,
KM

Replies are listed 'Best First'.
Re: Re: Re: replacing blank lines
by merlyn (Sage) on Mar 06, 2001 at 05:39 UTC
Re: Re: Re: replacing blank lines
by chipmunk (Parson) on Mar 06, 2001 at 08:20 UTC
    The first one-liner will not have the intended effect:     perl -pi -e 's,^\s+?$,,' file.txt only works on lines that consist of a newline. For lines that contain whitespace followed by a newline, the newline is not removed because of the non-greedy quantifier. (Although you could run the one-liner twice... ;)

    In the second one-liner:     perl -pi -e 's,^(\n|\s+)$,,g' file.txt the alternation and the /g are unnecessary.

    This is sufficient: perl -pi -e 's,^\s+$,,' file.txt