LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   sed used to remove a line from xml file (https://www.linuxquestions.org/questions/linux-general-1/sed-used-to-remove-a-line-from-xml-file-910002/)

nano2 10-25-2011 04:13 AM

sed used to remove a line from xml file
 
I have the following xml file where by i want to remove the following line from the file

This is what i have so far:

Code:

file.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
&lt;!DOCTYPE data PUBLIC &quot;  ....... &quot;
&lt;data1&gt;
&lt;data2&gt;
&lt;removeTxt value=&quot;1234567&2442_1==&quot; /&gt;
&lt;typeName=&quot;replace&quot; /&gt;
---
----


I am using sed to remove the following line "&lt;removeTxt value=&quot;1234567&2442_1==&quot; /&gt;" from the file.xml

Code:


    sed -i '/&lt;/removeTxt value=/<\/&gt;>/d' file.xml

But this doesn't seem to remove the line. Can anyone spot why not ?

jv2112 10-25-2011 04:26 AM

:twocents:

Your syntax appears to be off. Also the backslash toward the end needs to be escaped or sed will read as a deliminator. I have escaped below,with a bold /.

syntax

sed -i '/regex/d'

Quote:




sed -i '/&lt;removeTxt value=&quot;1234567&2442_1==&quot; //&gt;/d'




nano2 10-25-2011 05:27 AM

I just want to remove the line that has the value "removeTxt value" from the xml file

the above solution is specify the exact line content how can i just remove aline that has "removeTxt value" from xml file?

crts 10-25-2011 05:39 AM

Quote:

Originally Posted by nano2 (Post 4507528)
I just want to remove the line that has the value "removeTxt value" from the xml file

the above solution is specify the exact line content how can i just remove aline that has "removeTxt value" from xml file?

Code:

sed '/removeTxt value/d'
This will remove every line that contains 'removeTxt value'. If the results look ok then invoke 'sed' with the -i option to make the changes permanent.

nano2 10-25-2011 06:20 AM

With the below i am getting
sed: -e expression #1, char 28: expected newer version of sed

[code]
sed 'removeTxt value/d' file.xml
[\code]

using GNU sed version 4.1.5

Any ideas ?

crts 10-25-2011 06:29 AM

Quote:

Originally Posted by nano2 (Post 4507567)
With the below i am getting
sed: -e expression #1, char 28: expected newer version of sed

[code]
sed 'removeTxt value/d' file.xml
[\code]

using GNU sed version 4.1.5

Any ideas ?

Sorry, my bad. It should be
Code:

sed  '/removeTxt value/d' file.xml
I also corrected in in my previous post.

colucix 10-25-2011 06:30 AM

Missing leading slash in the command above:
Code:

sed '/removeTxt value/d' file.xml


All times are GMT -5. The time now is 02:49 AM.