mardi 27 octobre 2015

Two variables comparison, one-to-four possible outputs

I have two variables:

a=`echo 262832 6469180`
b=`echo 262832 263159 6469180 6469390`

hence:

echo $a
262832 6469180

echo $b
262832 263159 6469180 6469390

"b" represents four UTM coordinates, which are arranged from west to east, and from south to north (ie, W E S N). Variable "b" contains "a" only in two positions. Thus, after the comparison between "b" and "a" I need to print "1" and "3". The problem is that I also need to replace "1" and "3" by "W" and "S".

I do the comparison as follows:

if [[ $b == *"$a"* ]]
then
   echo "a is in b"
else
   echo "not there"
fi

but don't get the right idea to do the output replacement (it should be by columns as far as I understand).

Any pointers are welcomed,

Aucun commentaire:

Enregistrer un commentaire