Recently I came across an issue in grep. I was trying to match the pattern x.y.z and grep returned x.y-z.Using some regular expression we may can overcome this, but with grep whole word matching did not help. Since the script I was writing is a generic one, I cannot restrict search for a specific way as in like x.y.z or x.y-z ..
Quick way I figured is to run a grep and then a condition check
var="x.y.z"
var1=grep -o x.y.z file.txt
if [ $var1 == $var ]
echo "Pattern match exact"
else
echo "Pattern does not match exact"
fi
https://linuxacatalyst.blogspot.com/2019/12/grep-pattern-matching-issues.html