LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 10: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, 11:01 AM   #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, 07: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:18 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