Reputation: 619
I am trying to match two strings (IpAddress) as below. But it's not matching.
i=192.168.2.29
ipCheckInConfig="SG_1=192.168.2.24,192.168.2.29
> SG_2=192.168.2.20,192.168.2.23,192.168.2.31"
if echo "$i" | egrep -q "$ipCheckInConfig" ; then
echo "Matched"
else
echo "Not Matched"
fi
Could someone please help?
Upvotes: 1
Views: 2392
Reputation: 785098
You don't need to call egrep for that. Use bash's internal regex capabilities:
if [[ "$ipCheckInConfig" =~ $i ]]; then
echo "Matched"
else
echo "Not Matched"
fi
Upvotes: 4