Solved

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

Posted on 2011-02-10
4
436 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 167 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 167 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 26

Assisted Solution

by:wilcoxon
wilcoxon earned 166 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

726 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