--- usr.sbin/mergemaster/mergemaster.sh.orig
+++ usr.sbin/mergemaster/mergemaster.sh
@@ -1121,8 +1121,8 @@
     # If the files have the same $Id, delete the one in temproot so the
     # user will have less to wade through if files are left to merge by hand.
     #
-    ID1=`grep "[$]${ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
-    ID2=`grep "[$]${ID_TAG}:" ${COMPFILE} 2>/dev/null` || ID2=none
+    ID1=`grep -m1 -o "[$]${ID_TAG}:[^$]*[$]" ${DESTDIR}${COMPFILE#.} 2>/dev/null`
+    ID2=`grep -m1 -o "[$]${ID_TAG}:[^$]*[$]" ${COMPFILE} 2>/dev/null` || ID2=none
 
     case "${ID2}" in
     "${ID1}")
