Shell Script to Demonstrate RSS Reader
You may know that RSS is XML, which in itself is a simple tag language. XML elements are the values set by the marker. The tag contains any punctuation marks that start with a lower case – (<) and ends with a greater than sign (>). Tags are one of three types:
- Start tags, marking start value (like <item>).
- End tags, marking the end of value (</item>).
- “Empty item” tags, which may contain values as attributes (<feedburner: info url = “linuxjournalcom” />).
Shell Script to Demonstrate RSS Reader
Given an RSS XML File, the task is the parse the contents of the file
Sample Input: https://www.feedforall.com/sample.xml
Sample Output:
FeedForAll Sample Feed RSS Solutions for Restaurants <b>FeedForAll </b>helps Restaurant's communicate with customers. Let your customers know the latest specials or events.<br> Calendar of Events </i></font> RSS Solutions for Schools and Colleges FeedForAll helps Educational Institutions communicate with students about school wide activities, events, and schedules.<br> Lunches Menus </i></font> RSS Solutions for Computer Service Companies FeedForAll helps Computer Service Companies communicate with clients about cyber security and related issues. <br> Job Postings </i></font> RSS Solutions for Governments FeedForAll helps Governments communicate with the general public about positions on various issues, and keep the community aware of changes in important legislative issues. <b><i><br> Bulletins</i></font> RSS Solutions for Politicians FeedForAll helps Politicians communicate with the general public about positions on various issues, and keep the community notified of their schedule. <br> </i></font> RSS Solutions for Meteorologists FeedForAll helps Meteorologists communicate with the general public about storm warnings and weather alerts, in specific regions. Using RSS meteorologists are able to quickly disseminate urgent and life threatening weather warnings. <br> School Cancellations </i></font> RSS Solutions for Realtors & Real Estate Firms FeedForAll helps Realtors and Real Estate companies communicate with clients informing them of newly available properties, and open house announcements. RSS helps to reach a targeted audience and spread the word in an inexpensive, professional manner. <font color="#0000FF"><br> Mortgage Rates</i></font> RSS Solutions for Banks / Mortgage Companies FeedForAll helps <b>Banks, Credit Unions and Mortgage companies</b> communicate with the general public about rate changes in a prompt and professional manner. <br> Specials</i></font> RSS Solutions for Law Enforcement <b>FeedForAll</b> helps Law Enforcement Professionals communicate with the general public and other agencies in a prompt and efficient manner. Using RSS police are able to quickly disseminate urgent and life threatening information. <br> Meetings</i></font>
#!/bin/sh
# Akash 2022-02-13
# Url of the RSS feed RSS_URL=””
# Step 1 : Download RSS Feed
curl –silent “$RSS_URL” | \
# Step 2 : Only match lines with ‘title>’ or ‘description>’
grep -E ‘(title>|description>)’ | \
# Step 3 : Remove the first 3 lines tail -n +4 | \
#Other methods which use sed instead of tail
#sed -n ‘4,$p’ | \ #sed -e ‘1,3d’ | \
# Step 4 : Remove all leading whitespace from each line (spaces and tabs)
sed -e ‘s/^[ \t]*//’ | \
# Step 5 : Remove all title and description tags. ‘<description>’ is replaced with ‘ ‘ to indent it
sed -e ‘s/<title>//’ -e ‘s/<\/title>//’ -e ‘s/<description>/ /’ -e ‘s/<\/description>//’
The shell script for the above code can be written in a single line as indicated below
##Command all on one line: curl –silent “$RSS_URL” | grep -E ‘(title>|description>)’ | tail -n +4 | sed -e ‘s/^[ \t]*//’ | sed -e ‘s/<title>//’ -e ‘s/<\/title>//’ -e ‘s/<description>/ /’ -e ‘s/<\/description>//’
Snippets of running the Script:
Fig 1.1 Shell Script in a single line
Fig 1.2 Multi Line Script
Fig 1.2 Output of the parsed RSS Feed
Last Updated :
02 Mar, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...