[X-Unix] parsing help?

Wing Wong wingedpower at gmail.com
Thu Apr 27 18:11:28 PDT 2006


Hi Russell,

Definitely appreciate the thoughtfulness regarding size/length. :)

Hmm... not sure if this will take care of the spaces I'm seeing, but
those are probably due to pasting into email.. but I think the
following will convert it from one format to the other. I'm sure there
is a cleaner way to do it, but here is one way to do it:

cat source.csv | sed \
        -e 's/"","","","","","","","","","","","","","","","",/,/g' \
        -e 's/^/#HEAD#/'  | \
        tr '\012' ' ' | \
        sed \
        -e 's/^#HEAD#//' \
        -e 's/[ ]#HEAD#[,]/,/g' \
        -e 's/,[ ]*#HEAD#["]/, "/g' \
        -e 's/[ ]#HEAD#"/#BREAK#"/g' \
        -e 's/[ ]#HEAD#/ /g' \
        -e 's/#BREAK#/\n/g' \
        > processed.csv

I've wrapped the lines with "\"'s. So, hopefully, it will show up
correctly when it arrives in your inbox. I've attached a little script
that has the above code as an attachment. Alot of the "HEAD"
statements are to undo the line-breaks from posting into email, but
handles the line-breaks before the long sequence of "",'s. It's
probably the long way of doing it. :)

Wing

--
Wing Wong
wingedpower at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t_proc
Type: application/octet-stream
Size: 322 bytes
Desc: not available
Url : http://listserver.themacintoshguy.com/pipermail/x-unix/attachments/20060427/557b39ce/t_proc.obj


More information about the X-Unix mailing list