So, a few days ago at work I had this problem, I had a file containing many lines of dates in the following format:

mm-dd-yyyy but I had to convert it to yyyy-mm-dd and then join the sed and it’s arguments in a shell script (but I will not cover this shell script today, it is out of focus here).

To solve my problem, I just did the following:

#sed -e “s_\(..\)\-\(..\)\-\(….\)_\3-\1-\2_” sample.txt

Once I did it, I had my date format converted to the new one and sent to the output. So if you want it to be inserted in a new file, just add “>” after the file name, just like this:

#sed -e “s_\(..\)\-\(..\)\-\(….\)_\3-\1-\2_” sample.txt > sample_new.txt

Now you’ve got a new file containing ALL the lines in the new format! 😀