Skip to main content
changed the command so it actually runs
Source Link
Steven D
  • 47.6k
  • 15
  • 123
  • 117

If I've understood OP correctly, an empty line implies two consecutive newlines, \n\n.

If so, ondone possible solution would be to eliminate all singular occurrences of newlines.

In Perl, a lookahead assertion is one way to achieve this:

$ perl -0777 -pii -pe 's/\n(?=[^\n])//g' test
  • The -0777 flag effectively slurps the whole file into a single string
  • -p tells perl to print the string it's working on by default
  • -i specifies in-place editing
  • Global matching ensures that all single newline occurrences are dealt with

If I've understood OP correctly, an empty line implies two consecutive newlines, \n\n.

If so, ond possible solution would be to eliminate all singular occurrences of newlines.

In Perl, a lookahead assertion is one way to achieve this:

$ perl -0777 -pi 's/\n(?=[^\n])//g' test
  • The -0777 flag effectively slurps the whole file into a single string
  • -p tells perl to print the string it's working on by default
  • -i specifies in-place editing
  • Global matching ensures that all single newline occurrences are dealt with

If I've understood correctly, an empty line implies two consecutive newlines, \n\n.

If so, one possible solution would be to eliminate all singular occurrences of newlines.

In Perl, a lookahead assertion is one way to achieve this:

$ perl -0777 -i -pe 's/\n(?=[^\n])//g' test
  • The -0777 flag effectively slurps the whole file into a single string
  • -p tells perl to print the string it's working on by default
  • -i specifies in-place editing
  • Global matching ensures that all single newline occurrences are dealt with
fixed typo and unrelated changes due the stupid "edit is less than 6 chars" .. no, i just wanted to fix the typo.
Source Link

If I've understood OP correctly, an empty line implies two consecutive newlines, \n\n.

IsIf so, aond possible solution would be to eliminate all singular occurrences of newlines.

In Perl, a lookahead assertion is one way to achieve this:

$ perl -0777 -pi 's/\n(?=[^\n])//g' test
  • The -0777 flag effectively slurps the whole file into a single string
  • -p tells perl to print the string it's working on by default
  • -i specifies in-place editing
  • Global matching ensures that all single newline occurrences are dealt with

If I've understood correctly, an empty line implies two consecutive newlines, \n\n.

Is so, a possible solution would be to eliminate all singular occurrences of newlines.

In Perl, a lookahead assertion is one way to achieve this:

$ perl -0777 -pi 's/\n(?=[^\n])//g' test
  • The -0777 flag effectively slurps the whole file into a single string
  • -p tells perl to print the string it's working on by default
  • -i specifies in-place editing
  • Global matching ensures that all single newline occurrences are dealt with

If I've understood OP correctly, an empty line implies two consecutive newlines, \n\n.

If so, ond possible solution would be to eliminate all singular occurrences of newlines.

In Perl, a lookahead assertion is one way to achieve this:

$ perl -0777 -pi 's/\n(?=[^\n])//g' test
  • The -0777 flag effectively slurps the whole file into a single string
  • -p tells perl to print the string it's working on by default
  • -i specifies in-place editing
  • Global matching ensures that all single newline occurrences are dealt with
Source Link
Zaid
  • 11k
  • 13
  • 42
  • 36

If I've understood correctly, an empty line implies two consecutive newlines, \n\n.

Is so, a possible solution would be to eliminate all singular occurrences of newlines.

In Perl, a lookahead assertion is one way to achieve this:

$ perl -0777 -pi 's/\n(?=[^\n])//g' test
  • The -0777 flag effectively slurps the whole file into a single string
  • -p tells perl to print the string it's working on by default
  • -i specifies in-place editing
  • Global matching ensures that all single newline occurrences are dealt with