Hi, i have the below code that will compare the value from 2 variables:
./wlst.sh JMSmon.py > out.dat
w=`sed -e 's/\(.*!\)\(.*\)\(, Queue.*$\)/\2/' out.dat | awk '/'$1'/{n=0;{print $n}}'|head -n 1`
if [ $1 == $w ]
then
x=`sed -e 's/\(.*!\)\(.*\)\(, Queue.*$\)/\2/' out.dat | awk '/'$1'/{n=2;next}n{print $2;n--}' |head -n 1`
y=`sed -e 's/\(.*!\)\(.*\)\(, Queue.*$\)/\2/' out.dat | awk '/'$1'/{n=2;next}n{print $2;n--}' |tail -n 1`
z=`expr $x + $y`
echo $z
else
echo "-1"
fi
The variables are $1 and $w where $1 is the input string e.g. JMS.sh VAR1, so basically, if $1 is equal to $w then i dont have problem but if its not equal then ill have an output as below:
"JMS.sh[4]: test: 0403-004 Specify a parameter with this command.
-1"
i expected to have an output of "-1" only.
I suspect that its due to the command line:
w=`sed -e 's/\(.*!\)\(.*\)\(, Queue.*$\)/\2/' out.dat | awk '/'$1'/{n=0;{print $n}}'|head -n 1`
where $1 cannot find a match from out.dat then it threw some error.
Please advice how to go with this. I only want to have an output "-1" if $1 is NOT equal to $w.