Open In App

Shell Script to Demonstrate RSS Reader

Improve
Improve
Like Article
Like
Save
Share
Report

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  &lt;b&gt;FeedForAll &lt;/b&gt;helps Restaurant&apos;s communicate with customers. Let your customers know the latest specials or events.&lt;br&gt; Calendar of Events &lt;/i&gt;&lt;/font&gt; RSS Solutions for Schools and Colleges  FeedForAll helps Educational Institutions communicate with students about school wide activities, events, and schedules.&lt;br&gt; Lunches Menus &lt;/i&gt;&lt;/font&gt; RSS Solutions for Computer Service Companies  FeedForAll helps Computer Service Companies communicate with clients about cyber security and related issues. &lt;br&gt; Job Postings &lt;/i&gt;&lt;/font&gt; 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. &lt;b&gt;&lt;i&gt;&lt;br&gt; Bulletins&lt;/i&gt;&lt;/font&gt; 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. &lt;br&gt; &lt;/i&gt;&lt;/font&gt; 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. &lt;br&gt; School Cancellations &lt;/i&gt;&lt;/font&gt; RSS Solutions for Realtors &amp; 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. &lt;font color=&quot;#0000FF&quot;&gt;&lt;br&gt; Mortgage Rates&lt;/i&gt;&lt;/font&gt; RSS Solutions for Banks / Mortgage Companies  FeedForAll helps &lt;b&gt;Banks, Credit Unions and Mortgage companies&lt;/b&gt; communicate with the general public about rate changes in a prompt and professional manner. &lt;br&gt; Specials&lt;/i&gt;&lt;/font&gt; RSS Solutions for Law Enforcement  &lt;b&gt;FeedForAll&lt;/b&gt; 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. &lt;br&gt; Meetings&lt;/i&gt;&lt;/font&gt; 

#!/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
Previous
Next
Share your thoughts in the comments
Similar Reads