Hi all
I have some pipe-separated data in the form:
5/12/2008 00:00:00|31/1/2009 00:00:00|SOMESTUFF|OTHERSTUFF
12/31/2008 00:00:00|15/1/2009 00:00:00|MORESTUFF|REMAININGSTUFF
1/1/1023 00:00:00|16/5/2047 00:00:00|THEREST|YETMORE
I need to zero-pad the single-digit days and months, using sed.
I came up with this, but it does not handle the case where the datestamp appears in the first position in each record:
sed -e "s;\|\([1-9]\)\(\/[0-9]\{1,2\}\/[12][0-9]\{3\}\);\|0\1\2;g" \
-e "s;\([0-9]\{1,2\}\)\/\([1-9]\/[12][0-9]\{3\}\);\1/0\2;g" $DUMMYTMP > $TMPFILE
The 'month' code (the second -e statement above) works fine; my problem is with the day padding.
I need to tell sed to process the day value (i.e. pad it with a zero) if there is only a single digit prior to the first "/" in the date string, and to ignore the padding operation if there is more than one digit there.
Put another way, I need to something like:
s;(start of record|[^0-9])\([1-9]\)\(\/[0-9]\{1,2\}\/...
How do I express the optional start of record / non-digit part?
Any help appreciated. TIA.
James