Artificial intelligent assistant

Change date "July 29th, 2011" to "20110729" I have lots of HTML files contains date with format `July 29th, 2011` I want to change date format `July 29th, 2011` to `20110729`, `December 9th, 2010` to `20101209`, etc. I think `sed` may works but still can't find the solution because of its indirect sequence.

This sort of thing is much more difficult than it should be with most tools. GNU `awk` and Perl's POSIX module both give you a `strftime()`, but not a `strptime()`, which is what you want.

In any case, it is still pretty easy with Perl...


$ perl -MDate::Manip -lpe '$_=UnixDate(ParseDate($_), "%Y%m%d")' < > July 29th, 2011
> December 9th, 2010
> END
20110729
20101209


Obviously there's more to it, since you actually want to convert the HTML. If you can figure out a regex with sed that will work to _find_ the date strings, you should be able to do something very similar with Perl.


$ perl -MDate::Manip -lpe 's/(")([^"]+)(")/$1 . UnixDate(ParseDate($2), "%Y%m%d") . $3/ge' < dates enclosed "July 29th, 2011" in quotes
"December 9th, 2010"
END
dates enclosed "20110729" in quotes
"20101209"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 8790c9e87ca95ed6337346b26989c5ee