in reply to replace \n with space to join indented lines

If you want a one-liner then this may be what you want:
perl -lpe'BEGIN { $/ = "\n " } $\ = y/\n// ? $/ : $"'

Replies are listed 'Best First'.
Re^2: replace \n with space to join indented lines
by olivier (Initiate) on Dec 05, 2006 at 13:29 UTC
    Thank you very much jwkrahn. Your code works a treat. However, I do not understand it. Would you mind explaining it step by step please? Thank you olivier
      perl -lpe'
      Setup a while loop that automatically prints the current line and with the -l switch chomps the input and appends the output record separator.
      BEGIN { $/ = "\n " }
      Change the input record separator to a newline followed by four spaces.
      $\ = y/\n// ? $/ : $"'
      With the chomped line (after the input record separator has been removed), count the number of newlines. If there are no newlines then set the output record separator to the list separator (a single space), otherwise set the output record separator to the input record separator.

        That's great. Thank you very much indeed.