Hi RenMcCourtey,
Because by default ^ and $ only match at the beginning and end of the string, not each line within the string (I'm simplifying a little here - for the details see ^, $, and the /m modifier in perlre). This works:
perl -p0e 's/\n^\s*$//mg' input.txt
But requires you to read the entire file* into memory. I'd use:
perl -ne 'print if /\S/' input.txt
Hope this helps, -- Hauke D
* assuming it doesn't contain NUL characters |