vvar='{"floor":2,"hotelid":"3433bbb"}' #vvar='{"hotelid":"3433bbb","floor":2}' echo $vvar var21=`echo $vvar|awk -F ',' '{print $1}'` echo $var21 var31=`echo $var21|awk -F ':' '{print $2}'` echo $var31 var22=`echo $vvar|awk -F ',' '{print $2}'` echo $var22 var32=`echo $var22|awk -F ':' '{print $2}'` echo $var32 vv=`echo $var21|grep "floor"` echo $vv if [ $vv ]; then floor=$var31 hotelid=${var32%}*} else floor=${var32%}*} hotelid=$var31 fi echo $floor echo $hotelid