vendredi 8 juin 2018

Regex Bash to match a condition

I wish to match below patterns and then proceed for a shell script in Jenkins. The strings should always start with CMR- and SP- and should be followed up with 4 numbers like below. I am having problem in matching this case for a digit of upto 4 numbers in the range from 0-9. Any language will do.

Can someone please help me out?

CMR-1256 and SP-1278

My bash expression is like below.

end () {

exit 1

}

echo $CMR


if [ ! `echo $CMR | grep -cE "^CMR-{0,9}|^SP-{0,9}" ` -gt 0 -a $environment == "xyz" ]

then

echo "None of the conditions met"
   end 

  fi

Aucun commentaire:

Enregistrer un commentaire