Skip to main content
deleted 202 characters in body
Source Link
Joseph R.
  • 40.5k
  • 8
  • 113
  • 146

In perl

perl -n00Elp00e 'chomp;s's/\n/ /g;say'g' your_file

Explanation

  • l: Remove the input record separator from the current record being processed and add the current output record separator (a newline by default) after each printed line.
  • -np: Operate on the file record by record and print the current record after processing.
  • -00: Means the record separator is two or more consecutive newlines
  • -Ee : execute the following string as code while setting the default variable ($_) to the record currently being read from the file.
  • chomp: remove the record separator from $_
  • s/\n/ /g: Replace every newline encountered in the current record with a space (the g modifier ensures the replacement is "global").
  • say: Prints the contents of $_ with a newline added at the end. It is used here instead of print because chomp will have removed the newlines separating the different paragraphs. It is equivalent to print "$_\n".
  • We needed to use -E rather than -e because it enables the use of more recent language features; the say function in this case.

In perl

perl -n00E 'chomp;s/\n/ /g;say' your_file

Explanation

  • -n: Operate on the file record by record
  • -00: Means the record separator is two or more consecutive newlines
  • -E : execute the following string as code while setting the default variable ($_) to the record currently being read from the file.
  • chomp: remove the record separator from $_
  • s/\n/ /g: Replace every newline encountered in the current record with a space (the g modifier ensures the replacement is "global").
  • say: Prints the contents of $_ with a newline added at the end. It is used here instead of print because chomp will have removed the newlines separating the different paragraphs. It is equivalent to print "$_\n".
  • We needed to use -E rather than -e because it enables the use of more recent language features; the say function in this case.

In perl

perl -lp00e 's/\n/ /g' your_file

Explanation

  • l: Remove the input record separator from the current record being processed and add the current output record separator (a newline by default) after each printed line.
  • -p: Operate on the file record by record and print the current record after processing.
  • -00: Means the record separator is two or more consecutive newlines
  • -e : execute the following string as code while setting the default variable ($_) to the record currently being read from the file.
  • s/\n/ /g: Replace every newline encountered in the current record with a space (the g modifier ensures the replacement is "global").
added 4 characters in body
Source Link
Joseph R.
  • 40.5k
  • 8
  • 113
  • 146

In perl

perl -n00E 'chomp;s/\n/ /g;say' your_file

Explanation

  • -n: Operate on the file record by record
  • -00: Means the record separator is two or more consecutive newlines
  • -E : execute the following string as code while setting the default variable ($_) to the record currently being read from the file.
  • chomp: remove the record separator from $_
  • s/\n/ /g: Replace every newline encountered in the current record with a space (the g modifier ensures the replacement is "global").
  • say: Prints the contents of $_ with a newline added at the end. It is used here instead of print because chomp will have removed the newlines separating the different paragraphs. It is equivalent to print "$_\n".
  • We needed to use -E rather than -e because it enables the use of more recent language features; the say function in this case.

In perl

perl -n00E 'chomp;s/\n/ /g;say' your_file

In perl

perl -n00E 'chomp;s/\n/ /g;say' your_file

Explanation

  • -n: Operate on the file record by record
  • -00: Means the record separator is two or more consecutive newlines
  • -E : execute the following string as code while setting the default variable ($_) to the record currently being read from the file.
  • chomp: remove the record separator from $_
  • s/\n/ /g: Replace every newline encountered in the current record with a space (the g modifier ensures the replacement is "global").
  • say: Prints the contents of $_ with a newline added at the end. It is used here instead of print because chomp will have removed the newlines separating the different paragraphs. It is equivalent to print "$_\n".
  • We needed to use -E rather than -e because it enables the use of more recent language features; the say function in this case.
added 4 characters in body
Source Link
Joseph R.
  • 40.5k
  • 8
  • 113
  • 146

In perl

perl -p00en00E 'chomp;s/\n/ /g'g;say' your_file

In perl

perl -p00e 'chomp;s/\n/ /g' your_file

In perl

perl -n00E 'chomp;s/\n/ /g;say' your_file
Source Link
Joseph R.
  • 40.5k
  • 8
  • 113
  • 146
Loading