Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…

776 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