mikegray.397 mikegray.397 - 1 year ago 75
Python Question

Removing OU from group of ous using python

iam looking for python code to remove "var1" from "ougrpstr", please note that both variables will change i just want to strip var1 string from group.
basically "var1" representing a user and i am trying remove that user from a particular group.

var1= cn=656067688988,cn=Subscribers,cn=inc,cn=apac,cn=dac,cn=Resources,cn=Users,cn=OSILA
ougrpstr= "cn=656067689862,cn=Subscribers,cn=inc,cn=apac,cn=dac,cn=Resources,cn=Users,cn=OSILA;cn=656067680730,cn=Subscribers,cn=inc,cn=apac,cn=dac,cn=Resources,cn=Users,cn=OSILA;cn=656067688988,cn=Subscribers,cn=inc,cn=apac,cn=dac,cn=Resources,cn=Users,cn=OSILA;cn=656067686985,cn=Subscribers,cn=inc,cn=apac,cn=dac,cn=Resources,cn=Users,cn=OSILA"

cco cco
Answer Source

If an exact (case-dependent) match is OK, then you can use replace, as in:

newstr = ougrpstr.replace(var1, '')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download