in reply to Remove SOME new lines

And why this perl -p0e 's/\n^\s*$//g' nejms.txt doesn't remove blank lines? :-(

Replies are listed 'Best First'.
Re^2: Remove SOME new lines
by haukex (Archbishop) on Jun 29, 2016 at 12:26 UTC

    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

      Oh, thank you. I guess I'll have to start completely new question, being more descriptive.