in reply to Re: How do I remove blank lines from text files?
in thread How do I remove blank lines from text files?
Side note: using "/tmp/tmpfile.$$" as a temporary file name could have security implications if the program is running set-uid. For better ways of creating a temporary file name, see the FAQ How do I make a temporary file name?open FILE, "/path/to/file" or die "$!\n"; open OUT, "/tmp/tmpfile.$$" or die "$!\n"; while(<FILE>) { next if /^\s*$/; print OUT, $_; } close FILE; close OUT; rename("/path/to/file", "/path/to/file.bak") or die "Error in rename: $!\n"; rename("/tmp/tmpfile.$$", "/path/to/file") or die "Error in rename: $!";
Also, a regex is not necessary if you are looking for strictly empty lines. But many times, a line is considered empty even if it contains white space, in this case using regular expressions is the best way to do it.
--ZZamboni
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Re: How do I remove blank lines from text files?
by c-era (Curate) on Jul 11, 2000 at 20:57 UTC | |
by ZZamboni (Curate) on Jul 11, 2000 at 22:03 UTC |