On Tue, Nov 15, 2016 at 3:58 PM, Rich Shepard <[email protected]> wrote:
> The sed command worked on the first file (it took two runs to get all the
> dates, but what's another few milliseconds, eh?) but the second file has the
> dates in mm/dd/yyyy order.
>
> I modified the sed command to read:
>
> s#([0-9]{2})/([0-9]{2})/([0-9]{4})#\3-\1-\2#g
>
> and sed complains, "sed: file change-date-format.sed line 12: invalid
> reference \3 on `s' command's RHS".
>
> I thought that since the LHS clusters were numbered in sequence that the
> RHS would accept the groups in any order. Bad thought.
>
> How do I handle the different format?
>
> Here's a small data sample:
>
> ADAIR VILLAGE STP,WR,BENTON,101701,OR0023396,NPDES-DOM-DA,PERMIT,5/31/2011
> ADAIR VILLAGE STP,WR,BENTON,101701,OR0023396,NPDES-DOM-DA,PERMIT ACTION
> LETTER,5/31/2011
> ADAIR VILLAGE STP,WR,BENTON,101701,OR0023396,NPDES-DOM-DA,EVALUATION
> REPORT,5/31/2011
> ALBANY PAPER MILL,WR,LINN,101345,OR0000442,NPDES-IW-B01,PERMIT,9/30/2000
> ALBANY PAPER MILL,WR,LINN,101345,OR0000442,NPDES-IW-B01,EVALUATION
> REPORT,9/30/2000
> ALBANY STP,WR,LINN,102024,OR0028801,NPDES-DOM-BA,PERMIT,10/31/2005
> ALLVAC- ALBANY PLANT,WR,LINN,102223,OR0001716,NPDES-IW-B08,PERMIT,5/31/2006
> ALLVAC- ALBANY PLANT,WR,LINN,102223,OR0001716,NPDES-IW-B08,PERMIT,11/30/2015
Not bad thought. But your data does not match your assumptions. You
date is not in mm/dd/yyyy format, but rather m/d/yyyy format, where m
and d can be either 1 or 2 digits.
Add a "1," to your count restriction:
$ <<< '5/31/2011' sed -re 's#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})#\3-\1-\2#g'
2011-5-31
BTW, a really good book on regular expressions is "Mastering Regular
Expressions, 3rd Edition"
http://shop.oreilly.com/product/9780596528126.do
Regards,
- Robert
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug