[PLUG] Re-formatting Date in .csv Field

Tim tim-pdxlug at sentinelchicken.org
Tue Jan 25 22:31:09 UTC 2011


> Super hackish awk that I did in five minutes, but it seems to work... maybe...
> 
> awk '{split ($1, a, ","); split (a[4], b, "/"); printf
> "%s,%s,%s,%s-%s-%s,%s,%s,%s,%s\n", a[1], a[2], a[3], b[3], b[1], b[2],
> a[5], a[6], a[7], a[8]; }'
> 
> Give it a try, refine it (because it's fugly), your mileage may vary,
> yadda yadda...

Probably works in most cases, but Microsoft CSV is actually a
surprisingly complex format to parse.  Cells can contain new lines (as
part of data) as well as indirectly escaped commas.

I've had trouble convincing OOo to behave sanely when it comes to
formatting various fields.  If you can't do the conversion there, I'd
recommend just using Python's CSV module.  It defaults to using
Microsoft's escaping syntax on input and output.  I don't have time to
write the script right now, but it shouldn't take more than 5-6 lines
of code.

tim



More information about the PLUG mailing list