Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-10
4
Medium Priority
?
454 Views
Last Modified: 2012-05-11
I need to change Change the date format from 01-03-11 to 01-03-2011 format using shell or perl.
0
Comment
Question by:libertyforall2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 668 total points
ID: 34867903
echo 01-03-11 | perl -pe 's/(-\d+)-(\d+)/$1-20$2/'
0
 
LVL 23

Assisted Solution

by:savone
savone earned 668 total points
ID: 34867906
The date command can be formatted any way you like:

date +%m-%d-%Y

would output month-day-year like so:

02-10-2011

0
 
LVL 27

Assisted Solution

by:wilcoxon
wilcoxon earned 664 total points
ID: 34867942
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"'
0
 

Author Closing Comment

by:libertyforall2
ID: 34868192
It works thanks.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Six Sigma Control Plans
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question