in reply to Re: removing empty lines
in thread removing empty lines

Ok thank you! So tr does not do all regexp metachars such as \d \D \s +\S \w \W? is \s+ is whitespace, why didn't s/^\s+|\s+$//g work on these empty li +nes? So \S is non-whitespace so essentially it is ???

Replies are listed 'Best First'.
Re^3: removing empty lines
by MonkE (Hermit) on May 18, 2007 at 19:22 UTC
    Your substitute command is only operating on a single line. After it has removed all characters from the line, you are still left with a blank line. The "next if blank" approach works best for removing unwanted lines in my opinion.
Re^3: removing empty lines
by swampyankee (Parson) on May 19, 2007 at 01:05 UTC

    /^\s+$/ or /\s+$/ matches one or more whitespace characters; neither will match an empty line, i.e., one consisting solely of a newline (as would a line printed by print "\n";) won't be matched.

    emc

    Insisting on perfect safety is for people who don't have the balls to live in the real world.

    —Mary Shafer, NASA Dryden Flight Research Center