in reply to Re: Parsing Text into CSV
in thread Parsing Text into CSV

Oh, actually, I forgot - the code also has to deal with lines like
Last Login: (none) (interactive), (none) (non-in +teractive) Last Login: (none) (interactive), 12-SEP-1997 11:33 (non-in +teractive) Last Login: 11-JUL-2002 18:08 (interactive), (none) (non-in +teractive)
I figured I'd add to radiant.matrix's code like
/^Last Login:\s+.*,\s*(\d+.*?\:\d+)/ and print "$1,$2\n";
but it's giving an error 'Unrecognized escape \d passed through..' I figure adding a condition to BrowserUK's regexp would work, too...

Replies are listed 'Best First'.
Re^3: Parsing Text into CSV
by BrowserUk (Patriarch) on Jan 19, 2006 at 21:38 UTC

    And what output would you want in those cases? The text '(none)' where the date should be?

    #! perl -slw use strict; while( <DATA> ) { $_ .= <DATA>; print join',', m[ Username: \s+ (\S+) \s+ Owner: \s+ ([^\n]+ ) \n Last\sLogin: \s+ ( .+ ) \s \( [^,]+, \s+ (.+) \s\( ]x; } __DATA__ Username: JANDERSON Owner: JOE ANDERSON Last Login: 14-JAN-2002 08:14 (interactive), 4-MAR-2002 17:09 (non-in +teractive) Username: PBARRETT Owner: PAUL BARRETT Last Login: 18-JAN-2006 08:14 (interactive), 24-MAR-2005 17:09 (non-i +nteractive) Username: LARRY Owner: LARRY FINE Last Login: (none) (interactive), (none) (non-in +teractive) Username: MOE Owner: HARRY MOSES HOWARD Last Login: 11-JUL-2002 18:08 (interactive), (none) (non-in +teractive) Username: CURLY Owner: JEROME HOWARD Last Login: (none) (interactive), 12-SEP-1997 11:33 (non-in +teractive)

    Gives

    P:\test>junk JANDERSON,JOE ANDERSON,14-JAN-2002 08:14,4-MAR-2002 17:09 PBARRETT,PAUL BARRETT,18-JAN-2006 08:14,24-MAR-2005 17:09 LARRY,LARRY FINE,(none),(none) MOE,HARRY MOSES HOWARD,11-JUL-2002 18:08,(none) CURLY,JEROME HOWARD,(none),12-SEP-1997 11:33

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Yup, thanks, BrowserUK - that worked great :)