Unix Korn Shell - Converting Strings to Dates

I am pulling the Day,  Month , Year from various files using 'ls -l' to allow me to compare files in one directory against another.  The month is coming out as 'Oct'.  The problem is I need to convert my final string e.g. '10/May/2005' to a date format to allow me to filter which has the latest date etc.  I have trawled various sites with no answers.

I have used awk to extract the positions from ls-l process.   Any help appreciated....
btcodemanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oleggoldCommented:
You can use awk printf command to do that
0
ozoCommented:
echo '10/May/2005' | awk -F/ 'BEGIN{m["Jan"]=1;;m["Mar"]=3;m["Apr"]=4;m["May"]=5;m["Jun"]=6;m["Jul"]=7;m["Aug"]=8;m["Sep"]=9;m["Oct"]=10;m["Nov"]=11;m["Dec"]=12}{printf "%4d-%02d-%-2d",$3,m[$2],$1}'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
echo '10/May/2005' | awk -F/ 'BEGIN{m["Jan"]=1;;m["Mar"]=3;m["Apr"]=4;m["May"]=5;m["Jun"]=6;m["Jul"]=7;m["Aug"]=8;m["Sep"]=9;m["Oct"]=10;m["Nov"]=11;m["Dec"]=12}{printf "%4d-%02d-%02d",$3,m[$2],$1}'
0
NVRAMCommented:
You might step back and ask if you can get 'ls' to give what you want.  If you are using Linux, or GNU 'ls', you could try reformatting the output of 'ls' instead, as with:

    ls -l --time-style='+%Y/%m/%d-%M:%H:%S'

Which will give dates listed like this:    2006/03/17-10:06:03
0
btcodemanAuthor Commented:
Ozo,  thanks for the answer  - much appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.