http://www.perlmonks.org?node_id=844035


in reply to why does 'sed' remove the entire line?

What if you just used Perl? as long as you're in there, no reason at all to fork to sed: $line =~ s/\s+$//mg....