Solved

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

Posted on 2011-02-10
4
413 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now