Search code examples
regexbashawksedfind-replace

change date formats in text file with bash


I have a text file with thousands of random dates in MM/DD/YYYY format. I need to convert all of these dates to YY/MM/DD. What is the quickest and easiest way to do this using bash? Note that we will need to search for the dates because the file contains other text content as well.


Solution

  • Not even remotely robust, but you might try:

    perl -pe 's@\b(\d{1,2})/(\d{1,2})/\d\d(\d\d)\b@$3/$1/$2@' input