in reply to splitting cvs file without line breaks

Well, based on the sample snippet, there's was a line break just before each date, right? You could try

perl -pi.bak -e 's/ *(?:\d{4}-\d{2}-\d{2})/\r\n/g' filename

That inserts CRLF before the date at all instances and saves the original to filename.bak - see perlrun.

update: Oops, typo. I mean

perl -pi.bak -e 's/ *(?=\d{4}-\d{2}-\d{2})/\r\n/g' filename

Thanks, johngg!

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: splitting cvs file without line breaks
by johngg (Canon) on May 15, 2007 at 19:17 UTC
    s/ *(?:\d{4}-\d{2}-\d{2})/\r\n/g

    Perhaps I'm missing something but doesn't that replace the date rather than inserting before the date? Perhaps make the date a capture and replace with \r\n$1?

    Cheers,

    JohnGG

Re^2: splitting cvs file without line breaks
by Skeeve (Parson) on May 15, 2007 at 20:28 UTC

    using / * instead of / + might result in too many linefeeds being inserted.

    And why do you use \r\n insteat of just \n


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
      using / * instead of / + might result in too many linefeeds being inserted.

      Agreed.

      And why do you use \r\n insteat of just \n

      Well, that's because... well, er... :-)
      You're right again, probably inserting $/ makes more sense. But I've seen csv files that use "\r\n" as record separator, and "\n" as newlines inside fields.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}