?
Solved

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

Posted on 2011-02-10
4
Medium Priority
?
448 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 26

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

765 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