in reply to Re: how to convert new line to ","
in thread how to convert new line to ","

The shell command-line equivalent:
cat data.txt | perl -00pe 's/\\n/,/g'
Update: Oops! My mistake. I needed to add "-l" argument and also be careful of how the shell interprets '\n':
cat data.txt | perl -l -00pe 's/\n/,/g'

Replies are listed 'Best First'.
Re^3: how to convert new line to ","
by moritz (Cardinal) on Jul 25, 2008 at 08:40 UTC
    Did you actually test that?

    When I tried it did replace newlines with commas, but also the double newlines that bh_perl doesn't want to have replaced.

      The working line would be
      perl -00pe 'chomp; s/\n/,/g; s/$/\n/' data.txt
      and, yes, I tested it :-) the chomp yanks the last \n\n, so you must put one again at the end b4 printing.
      []s, HTH, Massa (κς,πμ,πλ)
        We can get around chomping with the "-l" argument.