in reply to Re: Remove SOME new lines
in thread Remove SOME new lines

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

Replies are listed 'Best First'.
Re^3: Remove SOME new lines
by RenMcCourtey (Acolyte) on Jun 29, 2016 at 12:32 UTC
    Oh, thank you. I guess I'll have to start completely new question, being more descriptive.