COnvert Month into a numeric value in Solaris
COnvert Month into a numeric value in Solaris
(OP)
Hi
I am looking for a short and neat program to convert Month Name like Sep to 09 in Solaris
I do not see any date function that can help. This can be for any month and not necessarily current month
I have tried Case statement it works but very messsy.
Input provided
Sep 09
Output expected
09 09
Thanks for your help in advance
Naveen
I am looking for a short and neat program to convert Month Name like Sep to 09 in Solaris
I do not see any date function that can help. This can be for any month and not necessarily current month
I have tried Case statement it works but very messsy.
Input provided
Sep 09
Output expected
09 09
Thanks for your help in advance
Naveen
RE: COnvert Month into a numeric value in Solaris
10 03
sun [721561]-> date
Mon Oct 3 12:02:43 MDT 2011
# for help:
sun [721562]-> man date
example% date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'
generates as output
DATE: 08/01/76
TIME: 14:45:05
Example 2: Setting the Current Time
The following command sets the current time to 12:34:56:
example# date 1234.56
A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"
bsh
37 years Bell, AT&T, Lucent, Avaya
Tier 3 for 27 years and counting
http://bshtele.com
RE: COnvert Month into a numeric value in Solaris
CODE
month_no()
{
typeset -u MON=$1
case $MON in
JAN) MNO=01;;
FEB) MNO=02;;
MAR) MNO=03;;
APR) MNO=04;;
MAY) MNO=05;;
JUN) MNO=06;;
JUL) MNO=07;;
AUG) MNO=08;;
SEP) MNO=09;;
OCT) MNO=10;;
NOV) MNO=11;;
DEC) MNO=12;;
*) MNO=XX;;
esac
print $MNO
}
month_no Jan
month_no jul
month_no SEP
month_no moocow
DT="Aug 20"
print "Original Date: ${DT}"
MO=${DT%% *}
DY=${DT##* }
DT="$(month_no ${MO}) ${DY}"
print "Converted Date: ${DT}"
RE: COnvert Month into a numeric value in Solaris
I have this code currently .I am looking at an alternative like a one or few lines of code with Awk ..etc
Cheers
Naveen
RE: COnvert Month into a numeric value in Solaris
Whenever someone turns down a working solution because it's not a specific method, it's often because it's a homework assignment.
RE: COnvert Month into a numeric value in Solaris
No. Its not honestly. I am looking for a alternative as i could not figure one .
I am using this as input to a touch command which create a file dd .Based on that start timestamp i have to find files that has changed in a given interval.There can be multiple logfiles.It works fine with this date format (10/6/11 20:15 10/6/11 23:15)
but when i give Oct 6 20:15 Oct 6 23:15 you can see i have to write such a long Proram to convert Month to number so Touch can understand
Hope i have justified
Input given to program
10/6/11 20:15 10/6/11 23:15
===================program snippet ===================
touchdate=$3
touchtime=$4
echo " date is $touchdate"
echo "Time is $touchtime"
echo "touch -t "$3""$4" $HOME/dd"
touch -t "$3""$4" $HOME/dd
find . -type f -newer $HOME/dd |awk -F'/' '{print $2}'
RE: COnvert Month into a numeric value in Solaris
CODE
See the man page for "touch" for more info.
RE: COnvert Month into a numeric value in Solaris
Touch command works for the specified Date formatwith the format i have in the script .And also for the Month (I have same program as yours)
I have no issues reported by touch (bad command argument ..etc)
Anyway i think i am still looking for a shortcut.I will post once i figure out
Cheers
naveen
RE: COnvert Month into a numeric value in Solaris
CODE
awk 'BEGIN { month["Jan"]="01" ; month["Feb"]="02" ; month["Mar"]="03" ; month["Apr"]="04" ; month["May"]="05" ; month["Jun"]="06" ; month["Jul"]="07" ; month["Aug"]="08" ; month["Sep"]="09" ; month["Oct"]="10" ; month["Nov"]="11" ; month["Dec"]="12" } { print month[$1], $2 }'