LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-25-2011, 04:13 AM   #1
nano2
Member
 
Registered: May 2007
Posts: 100

Rep: Reputation: 15
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 ?
 
Old 10-25-2011, 04:26 AM   #2
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
Lightbulb



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'


 
Old 10-25-2011, 05:27 AM   #3
nano2
Member
 
Registered: May 2007
Posts: 100

Original Poster
Rep: Reputation: 15
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?

Last edited by nano2; 10-25-2011 at 05:28 AM.
 
Old 10-25-2011, 05:39 AM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by nano2 View Post
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.

Last edited by crts; 10-25-2011 at 06:29 AM. Reason: typo
 
Old 10-25-2011, 06:20 AM   #5
nano2
Member
 
Registered: May 2007
Posts: 100

Original Poster
Rep: Reputation: 15
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 ?
 
Old 10-25-2011, 06:29 AM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by nano2 View Post
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.
 
Old 10-25-2011, 06:30 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Missing leading slash in the command above:
Code:
sed '/removeTxt value/d' file.xml
 
  


Reply

Tags
bash sed find



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] using sed to extrac data from xml tags and make the result displayed in one line pikcolo Linux - Newbie 5 04-20-2011 01:27 AM
Remove sections of a xml file with sed viniciusandre Linux - Software 2 04-20-2009 01:18 PM
using sed to remove line in a comma-delimited file seefor Programming 4 03-10-2009 03:35 PM
PHP Remove Line From Shoutcast Playlist File. Sed? windisch Programming 2 03-26-2007 08:52 PM
How to remove single-line XML nodes from files dfrechet Programming 1 10-11-2005 02:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration