A Sed One Liner to Fix Date Format in Text Files
SoftwareTL;DR This is a know your tools entry, although I absolutely don’t know my tools as you will see if you read.
The following “one-liner” will change any wiki style link with a date string formatted as “Feb 22nd, 2024” to “2024-02-22”, god’s intended way to write a date.
Please forgive the search and replace gore of the second sed.
1sed -E 's;([a-zA-Z]{3})\s([0-9]{1,})(st|nd|rd|th),\s([0-9]{4});\4-\1-\2;' "$1" | 2 sed -E 's/-Jan-/-01-/;s/-Feb-/-02-/;s/-Mar-/-03-/;s/-Apr-/-04-/;s/-May-/-05-/;s/-Jun-/-05-/;s/-Jul-/-07-/;s/-Aug-/-08-/;s/-Sep-/-09-/;s/-Oct-/-10-/;s/-Nov-/-11-/;s/-Dec-/-12-/' | 3 sed -E 's;-([0-9])\];-0\1];' > "$1".
Read more...