in reply to replace multiple newline characters

Provided your input-file is small enough to be read into memory, you can do this with a one-liner:
perl -i.old -0777 -pe 's/\n+/\n/sg' input.txt
the original version of the file is kept as input.txt.old.

Replies are listed 'Best First'.
Re^2: replace multiple newline characters
by hippo (Archbishop) on May 15, 2018 at 08:15 UTC
    Provided your input-file is small enough to be read into memory

    Here's one without that constraint:

    perl -i.old -ne 'print if /./;' input.txt

        Shorter, yes, but it looks like you've re-introduced the "input-file is small enough to be read into memory" constraint. Or have I missed something?