Modify sections of the line in a file

Hello..
I have a line in a file which I have to edit:

the line looks like:
<![CDATA[(&(|(cn=ABC)(cn=DEF))(objectclass=groupOfUniqueNames))]]>

Sometimes, the section of the line can have only one entry for cn, or maybe more than 2 like below:
<![CDATA[(&(|(cn=ABC))(objectclass=groupOfUniqueNames))]]>

I have a variable which has the following value:
CN="(cn=MNO)(cn=XYZ)"

I need to replace the part of the line (cn=ABC)(cn=DEF) with $CN

Please help!

Thanks,
Chiru

sed "s/\(<.*|\)\((cn=.*\)\()\)\((.*>\)/\1$CN\3\4/p" file

is this a cognos application? i used to work with cognos 8 before.

Hi
I need to modify entire file starting from the 3 line. file looks like this
filename : exp

first line
second
1,"wes","est","ws"
1,"was","qwe","qwa"

also i have to replace the third content from 3 line by a counter . so the output should look like this:

first line
second
1,"wes","1","ws"
1,"was","2","qwa"

here 1, 2 is a type of incrementing counter ...

please help :frowning:

please create new thread