Live Scores
Shareware
Movie Stars
in
Miscellaneous
Progamming
(Entire Site)
Questions and answers to issues related to Microsoft: Windows, Applications, Development, Hardware, Server, Internet Protocols, Database, Exchange .
»
Progamming
»
Miscellaneous
»
Unix Korn Shell - Converting Strings to Dates
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....
Solution: Unix Korn Shell - Converting Strings to Dates
echo '10/May/2005' | awk -F/ 'BEGIN{m["Jan"]=1;;m["Mar"
]=3;m["Apr
"]=4;m["Ma
y"]=5;m["J
un"]=6;m["
Jul"]=7;m[
"Aug"]=8;m
["Sep"]=9;
m["Oct"]=1
0;m["Nov"]
=11;m["Dec
"]=12}{pri
ntf "%4d-%02d-%-2d",$3,m[$2],$
1}'