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?
Asked
Active
Viewed 362 times
2 Answers
2
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.

Raman Sailopal
- 12,320
- 2
- 11
- 18
0
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)

Joe
- 29,416
- 12
- 68
- 88
-
This gives me the following error (pasted in pastebin): https://pastebin.com/Yk3GKFwA I'm using macOS – twlscnds Nov 06 '20 at 13:20
-
1@twlscnds Add a `-` at the end so `xmllint` knows to read from STDIN. Rewritting the first command: `curl http://feeds.macrumors.com/MacRumors-All | xmllint --xpath '/rss/channel/item[1]/title/text()' -` – user137369 May 31 '23 at 12:01