Hi,
i want to replace sub text which is in the middle of long text.
let me be more clear with an example.
Here is the actual text in the xml file
<module-option name="principalDNSuffix">,cn=Users,dc=X,dc=Y</module-option>
Now, in the above text, i want to replace all the content lying between <module-option name="principalDNSuffix">, and </module-option>
Please can some one help me to understand how to achive this using sed.
Try this,
sed 's/\(<module-option name="principalDNSuffix">,\)\(.*\)\(<\/module-option>\)/\1replace\3/' inputfile
thanks.
I used the same but That din't work.
Here is a two step process. I am sure this can be done in single step also:
File
$cat 1.txt
<module-option name=principalDNSuffix>,cn=Users,dc=X,dc=Y</module-option>
Script
$sed -e 's:\(<module-option name=principalDNSuffix>\)::g' -e 's:\(<\/module-option>\)::g' < 1.txt > 2.txt
touch trim_log.txt
for i in `cat 2.txt`
do
sed s:$i::g < 1.txt >> trim_log.txt
done
Output
$cat trim_log.txt
<module-option name=principalDNSuffix></module-option>