I'd like to make validation about time stamp of one of my log file. But it seems I have problem on my expression in case statement.
TIME value might be something like 11:49 or 2011. And I just want to check whether it is HH:MM format or not. Code is in below.
It is always saying year format althought file is in HH:MM format
#!/usr/bin/ksh
TIME=`ls -lrth /var/log/*.log | grep -i upg | tail -1 | awk '{print $8}'`
echo "$TIME"
validation=false
if [[ $TIME != "" ]]
then
case TIME in
"[0-23]+ :[0-59]")
validation=true
break;;
*) echo "Year format";;
esac
fi
echo "$validation
Update : I tried "[0-2][0-9]:[0-5][0-9]") but validation still return fail.
globstyle expressions andregularexpressions. The bashcasestatement uses regular expressions. You need to remove the "quotes" ... bash regular expressions need to be exposed; not protected by quotes... If you need spaces, just escape them with\– Peter.O Jul 18 '12 at 13:02caseuses aglobstyle expression. – Peter.O Jul 18 '12 at 15:07[0-23]means "only 1 char matching" either 1). the range 0-2 (i.e. 0,1,2) OR 2) the single number number 3, NOT0 hrs to 23 hrsas I'm guessing you mean. ---- Inside sq-brackets, each char stands for itself as a match for one char, excepting when the range notation is use as0-2. You can use reg expers in this case to get mostly what you want, iecase TIME in [0-2][0-9]\ :[0-5][0-9]). Read it one sq-brkt at a time, what ever inside is a single match. GL. – shellter Jul 19 '12 at 4:38