I have a file in linux with similar entries as below
dn: CN=HP_NetworkSupport,OU=groups,DC=HDFCSLDM,DC=COM dn: CN=Review users,OU=groups,DC=HDFCSLDM,DC=COM <
This is one way with lookahead:
grep -Po '(?<=CN=)[^,]*' file > new_file
It gets all text from CN= (not included) until it finds a comma ,. The idea of [^,]* is to fetch any character that is not a comma.
CN=
,
[^,]*
$ grep -Po '(?<=CN=)[^,]*' file HP_NetworkSupport Review users