Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm working on migrating from MDaemon to Google Apps. As part of this process I'm exporting the contacts and calendars for all of our users into CSV files then reading them into a perl script and importing them into Google Apps.

Here's a sample calendar export shown in vi with ":set list" on.

"Event 1","05/05/2009","0:00:00","05
/05/2009","23:59:00","True","True","05/04/2009","23:45:00",,,,"",,,"False","Normal",0$
"Event 2","09/21/2009","11:00:00","09/21/2009","11:30:00","False","False",,,"email@TELUS.COM","",,"Notes from=A0^M$
Vendor=A0",,"","False","Normal",1$
"Event 3","04/05/2010","0:00:00","04/05/2010","23:59:00","True","True","04/04/2010","23:45:00",,,,"",,,"False","Normal",0$
"Event 4","05/05/2010","0:00:00","05/05/2010","23:59:00","True","True","05/04/2010","23:45:00",,,,"",,,"False","Normal",0$

I'm running into trouble with the lines ending in ^M$ which are supposed to be embedded line endings. My CSV parser Text::CSV_XS is parsing them as multiple lines rather than a single line. How can I replace the ^M$ with ^M? Any other suggestions are welcome.

Here's my parsing code:

 my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/,auto_diag => 1 }) or
 die "Cannot use CSV: ".Text::CSV_XS->error_diag ();
 open my $fh, "<", $username . "-calendar.csv" or die $!;
 while (my $row = $csv->getline ($fh)) {
        print STDERR "NEW LINE: " . Dumper($row) . "END NEW LINE\n";
     push @rows, $row;
     }
 $csv->eof or $csv->error_diag ();
 close $fh;

UPDATE 1: Here's the output from "file" regarding this file:

Non-ISO extended-ASCII English text, with very long lines, with CRLF, LF line terminators

share|improve this question
1  
If you want unix line endings, check out dos2unix. It's a pretty nifty tool. –  VenkatH May 22 '12 at 18:38
    
I've tried running dos2unix on this file but it doesn't seem to affect the file. –  dkwiebe May 22 '12 at 19:36
    
Give this a try? Change file format in Vim –  VenkatH May 23 '12 at 16:47
    
That didn't do it either. I got it working with s/\r\r\n/<br>/g to replace the embedded line breaks with an html <br>. –  dkwiebe May 25 '12 at 20:06
add comment

1 Answer

up vote 0 down vote accepted

I got it working with s/\r\r\n/<br>/g to replace the embedded line breaks with an html <br>.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.