LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 12-11-2009, 11:37 AM   #1
noob_soni
LQ Newbie
 
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
read file and filter out specific tags in file


I am a newbie in shell scripting and would appreciate a help with this qstn. many thanks in advance and apologies for the big input file.
I have a .xml file that is a concat of multiple rss files. reqrmnt is to filter out all extra content in the file and keep only the actual items.

eg:
<?xml version="1.0" encoding="iso-8859-1"?>
<rss>
...........
some text here
<channel>
..........
some more tags here
<item>
<title>Item Example 1</title>
<link>http://www.domain.com/link1.htm</link>
</item>
<item>
<title>Item Example 2</title>
<link>http://www.domain.com/link2.htm</link>
</item>
</channel>
</rss>
<rss>
.....
some other tags
......
<item>
<title>Item Example 3</title>
<link>http://www.domain.com/link3.htm</link>
</item>
.......
more tags
.......
<item>
<title>Item Example 4</title>
<link>http://www.domain.com/link4.htm</link>
</item>
<item>
<title>Item Example 5</title>
<link>http://www.domain.com/link5.htm</link>
</item>
</rss>

//item can have more attribs

output should be:
<item>
<title>Item Example 1</title>
<link>http://www.domain.com/link1.htm</link>
</item>
and other items

much thanks,
Soni
 
Old 12-11-2009, 12:01 PM   #2
Web31337
Member
 
Registered: Sep 2009
Location: Russia
Distribution: Gentoo, LFS
Posts: 399
Blog Entries: 71

Rep: Reputation: 65
grep -v rss ?
i think if your format of RSS is static(one tag per line) it's quite simple to remove unwanted tags with grep, unless format will change to, say, single-line, where you will need to either use hard regexes or external programming lang.
 
Old 12-11-2009, 08:25 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
$ awk '/<\/item>/{f=0}/<item>/{f=1}f ' file
 
  


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
Shell script for read user data with emptyLines in a text file and filter them srimal Linux - Newbie 7 11-01-2009 05:37 AM
Shell script to read lines in a text file and filter user data srimal Linux - Newbie 5 10-21-2009 08:41 AM
display lyrics in banshee(read from 1d3 tags or txt file) sica07 Linux - Software 0 09-23-2009 04:59 AM
Does there a software which read RNG format to auto complete tags in XML file? nadavvin Linux - Software 0 11-02-2006 01:49 PM
Read specific lines from a text file chobin Programming 8 06-14-2006 12:14 PM


All times are GMT -5. The time now is 05:49 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration