Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-11-2009, 10:37 AM   #1
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.

<?xml version="1.0" encoding="iso-8859-1"?>
some text here
some more tags here
<title>Item Example 1</title>
<title>Item Example 2</title>
some other tags
<title>Item Example 3</title>
more tags
<title>Item Example 4</title>
<title>Item Example 5</title>

//item can have more attribs

output should be:
<title>Item Example 1</title>
and other items

much thanks,
Old 12-11-2009, 11:01 AM   #2
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
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

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


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 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 > Forums > Linux Forums > Linux - Newbie

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

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