Change 01-03-11 to 01-03-2011 format using shell or perl

I need to change Change the date format from 01-03-11 to 01-03-2011 format using shell or perl.
Who is Participating?
ozoConnect With a Mentor Commented:
echo 01-03-11 | perl -pe 's/(-\d+)-(\d+)/$1-20$2/'
savoneConnect With a Mentor Commented:
The date command can be formatted any way you like:

date +%m-%d-%Y

would output month-day-year like so:


wilcoxonConnect With a Mentor Commented:
Or a windowed approach...

echo 01-03-11 | perl -pe 'die "invalid date $_" unless m{^([-\d]+-)(\d+)$}; $_ = ($2 < 50) ? "${1}20$2" : "${1}19$2"'
libertyforall2Author Commented:
It works thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.