Skip to content

Instantly share code, notes, and snippets.

@Emonshr
Forked from megasaturnv/parseRssFeed.sh
Last active January 13, 2023 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Emonshr/aa747d1f8da7beeeab4ce41caed3edbb to your computer and use it in GitHub Desktop.
Save Emonshr/aa747d1f8da7beeeab4ce41caed3edbb to your computer and use it in GitHub Desktop.
Shell script / one-liner to parse and display an rss feed. May require tweaking for RSS feeds without newlines or where <title> and <description> are on separate lines to their text.
#!/bin/sh
#Megasaturnv 2017-07-28
#emonshr 13-01-23 (DD-MM-YY)
#Url of the RSS feed
RSS_URL="https://feeds.bbci.co.uk/news/world/rss.xml"
##Commented version:
#Download the rss feed
curl --silent "$RSS_URL" | \
#Only match lines with 'title>' or 'description>'
grep -E '(title>|description>)' | \
#Remove the first 3 lines
tail -n +4 | \
#Other methods which use sed instead of tail
#sed -n '4,$p' | \
#sed -e '1,3d' | \
#Remove all leading whitespace from each line (spaces and tabs)
sed -e 's/^[ \t]*//' | \
#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>//' \
##removing ugly xml CDATA
sed 's/<\!\[CDATA\[//' | sed 's/\]\]>//'
###############################
##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>//'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment