On Tue, 25 Jan 2011, Sam Hart wrote:

> 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...

Sam,

   I'm stuck on the 'yadda yadda' part. I've looked in my copy of 'sed & awk'
by Dougherty and Robbins without seeing the answer to two questions that
have come up.

   Here's another line where one field is a string with an embedded comma.
Awk takes that as the field separator ignoring all double quotes in the
input line:

NULL,"96-A001787","BC-0.5",6/25/1996,"Alkalinity, Bicarbonate",212,"mg/L 
CaCO3",NULL

The script output therefore is:

NULL,"96-A001787","BC-0.5",1996-6-25,"Alkalinity,,,

   Second question whose answer I must have missed in the book is how to
surround the reformatted date in double quotes. The whole printf string is
quoted; do I escape internal quotes so the printf statement reads,

"%s,%s,%s,\"%s-%s-%s\",%s,%s,%s,%s\n" ?

Thanks,

Rich
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to