I am trying to get only the groups that are in the grouplist to be in the variable FilterIDgroups. Sorry the variable names are bad, I had to change them to post them online.
Alas you are leaving out the essential part - the contents of IDgroups . And, I'm nor sure I understand the underlying logics. Do you want a "logical AND" of the two group lists: grouplist and IDgroups?
BTW, the redirection >> $FilterIDgroups will fail as you assigned the empty string to FilterIDgroups.
---------- Post updated at 17:05 ---------- Previous update was at 17:02 ----------
And, you could eliminate a big portion of your code snippet by using an array:
IFS="|" grouparr=($grouplst )
while (( cntr < ${#grouparr[@]} )); do echo ${grouparr[((cntr++))]}, $cntr; done