Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do I strip all the lines that don't contain anything from a txt file?
perl -e 's/^\s+$//' < file.txt
doesn't do anything.

Replies are listed 'Best First'.
Re: delete empty lines from a txt file
by broquaint (Abbot) on Nov 14, 2001 at 00:31 UTC
    You'll be wanting to use that lovely inplace edit switch -i
    perl -i -ne 'print unless /^\s+$/' your_file.txt
    For more info on that ever-handy switch checkout perlrun.
    HTH

    broquaint

      Notice that broquaint also sneaked in the -n flag there. That's the one that actually sets up a loop that processes the file a line at a time.

      And just to be obtuse, I'd write it like this:

      perl -i.bak -ne 'print if /\S/' your_file.txt
      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you don't talk about Perl club."