Reputation: 121
How can I get the title of an RSS feed with Bash? Say I want to get the most recent article from MacRumors. Their RSS feed link is http://feeds.macrumors.com/MacRumors-All
. How can I get the most recent article title with Bash?
Upvotes: 0
Views: 620
Reputation: 31087
You can combine curl
and an XPath expression (here, using xmllint
), and rely on the fact that the feed is in reverse chronological order:
curl http://feeds.macrumors.com/MacRumors-All | xmllint --xpath '/rss/channel/item[1]/title/text()' -
See How to execute XPath one-liners from shell? for other ways to evaluate XPath.
In particular, if you have an older xmllint
without --xpath
, you may be able to use the technique suggested by this wrapper:
echo 'cat /rss/channel/item[1]/title/text()' | xmllint --shell <(curl http://feeds.macrumors.com/MacRumors-All)
Upvotes: 0
Reputation: 12877
An alternative to xmllint is xmlstarlet and so:
curl -s http://feeds.macrumors.com/MacRumors-All | xmlstarlet sel -t -m "/rss/channel/item[1]" -v "title"
Use the xmlstarlet sel command to select the xpath we are looking for and then use -v to display a specific element.
Upvotes: 2