LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-05-2010, 08:09 AM   #1
guessity
Member
 
Registered: Dec 2009
Posts: 41

Rep: Reputation: 15
Question Need help with SED command to remove text


Hi Again,
I got stuck again with SED and I need a lil' help.

I have the following file named y.xml

Code:
<?xml version="1.0" encoding="iso-8859-1"?> <rss version="2.0"> <channel> <title>News</title> <lastBuildDate>Tue, 21 Jul 2009 16:32:47 Asia/Singapore</lastBuildDate><art>201002041656400001">
</art><aut>ANI</aut>
<item><title>Oh My God!!</title>
<cats>
Lifestyle
</cats>
<subcats>
Washington
</subcats>
<description><![CDATA[<p>
God</p>
]]></description></item></channel></rss>
<?xml version="1.0" encoding="iso-8859-1"?> <rss version="2.0"> <channel> <title>News</title> <lastBuildDate>Tue, 21 Jul 2009 16:32:47 Asia/Singapore</lastBuildDate><art>201002041656400018">
</art><aut>ANI</aut>
<item><title>twitter now</title>
<cats>
Tech
</cats>
<subcats>
Washington
</subcats>
<description><![CDATA[<p>
oh out here</p>
]]></description></item></channel></rss>
I am trying to fix the xml feed by trying to remove
Code:
</channel></rss>
<?xml version="1.0" encoding="iso-8859-1"?> <rss version="2.0"> <channel> <title>News</title> <lastBuildDate>Tue, 21 Jul 2009 16:32:47 Asia/Singapore</lastBuildDate><art>201002041656400018">
</art><aut>ANI</aut>
I used SED with the following -

Code:
sed -n '/</channel></rss>/,/</art><aut>ANI</aut>/p' y.xml
I get weird output. The xml can have any number of items. Any idea where i went wrong?

Can someone help me with SED or any other ways to remove those lines as I cant seem to figure out.
 
Old 02-05-2010, 08:25 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
"sed -n" means do not print unless instructed, and "p" means print. Thus your expression does the opposite of what you intended.

You want something like this:
sed '/start/,/stop/ d'

the second problem is the "/" characters inside the two addresses. These need to be escaped so they are not confused with the boundaries of the addresses. e.g.:

/<\/channel><\/rss>/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to remove words in a file using sed or any other command Kilam orez Linux - Newbie 4 11-30-2009 09:52 AM
[SOLVED] sed or awk help - need to remove text on each line before a regular expression kmkocot Linux - Newbie 15 10-30-2009 04:20 AM
[SOLVED] Using sed to remove text in fgrep string manwithaplan Linux - General 6 10-11-2009 02:00 AM
SED, regexp or such - remove text after space aolong Linux - General 5 03-07-2008 03:36 PM
help with sed to remove all text except for some Benanzo Linux - Software 7 01-04-2007 07:21 AM


All times are GMT -5. The time now is 08:31 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration