2008-02-05

How to parse RSS 2.0 in bash

It is quite easy to use information from RSS feeds in bash scripts. I use xmlstarlet to work with XML in the shell. For example, to print the latest titles and links from my RSS feed, I can do:
RSS_URL=http://feeds.feedburner.com/usefreetools
wget ${RSS_URL} -O - 2>/dev/null | \
xmlstarlet sel -t -m "/rss/channel/item" \
  -v "guid" -n -v "pubDate" -n -v "title" -n -v "link" -n -n
Alternatively, I can use curl -g ${RSS_URL} -s instead of wget. I could have added -v "description" to see the contents of my posts.