Problem cutting & comparing values

Hi guys

I am having some problem cutting and comparing values.I got an INI file which is has some values and ranges mapping to error and warning codes

eg
criticalerror:69,20,1to9
warningmsg:101,10to19

So taking the scenrio where i have a control script that execute a.ksh, when a.ksh returns a value , in this case 8, i need to map the return code to the critical error that is within the range 1 to 9.

And i have having a tough time trying to cut using expr or awk toactually retrive the 1 to 9 and using it to compare. My approach is to do something and retrive 1 and 9 and use it to compare the return code.however i am having rather diffculty cutting and comparing.

Can anyone out there help me out ?

regards
wilson

Script requires an input: the error number.
range.txt contains all the error types.

[/tmp]$ cat extract.ksh 
#! /bin/ksh

(($#)) || { echo "Input an error number" ; exit 1 ; }

err=$1

while read line
do
        range=${line##*,}
#       echo "$range"
        min=${range%%to*}
#       echo $min
        max=${range##*to}
#       echo "$max"

        if [ $err -ge $min -a $err -le $max ] ; then
        echo "Error type: ${line%%:*}"
        break ;
        fi ;

done < range.txt

exit 0;

If you enter an error number outside the range, it will return nothing.

Hi Vino,

thanks for the quick reply, 1 question, is my range.txt supposed to have values like this ? criticalerror:20to29

as i am getting a badnumber error despite entering values within the range

The range.txt should have entries in the manner you specified i.e.

criticalerror:69,20,1to9
warningmsg:101,10to19

The delimiter is a ,

If it is to be in the manner like

criticalerror:20to29

then change the delimiter to : i.e. range=${line##,} to range=${line##:}

Hi Vino,

thanks for the help it works, just curious what happens in if my INI file has the following format

criticalerror:69,20,1to9
warningmsg:10to19

what will i use to delimit ??

Simple.

Your delimiter would be :

After that, you check for the presence of a , and take the route of range=${line##,}. Else go down on this lane range=${line##:}

one more,

# !/usr/bin/ksh

mesg=""
first=0
last=0
notfound=1

while read line
do
mesg=`echo $line | sed 's/:.*//'`
echo $line | sed -e 's/^.*://;s/\(.*\),\(.*\),\(.*\)to\(.*\)/\3 \4/' | read first last

if [ \( $1 -ge $first \) -a \( $1 -le $last \) ]
then
echo "message is $mesg"
notfound=0
fi

done < ini

if [ $notfound -eq 1 ]
then
echo "unable to find message"
fi

exit 0
>cat ini
criticalerror:69,20,1to9
warningmsg:101,1,10to19