View the newest xkcd comic.

gwenview `wget -O - http://xkcd.com/ | grep 'png' | grep '<img src="http://imgs.xkcd.com/comics/' | sed s/title=\".*//g | sed 's/.png\"/.png/g' | sed 's/<img src=\"//g'`
Output the html from xkcd's index.html, filter out the html tags, and then view it in gwenview.
Sample Output
[hunterm@saturn ~ )> gwenview `wget -O - http://xkcd.com/ | grep 'png' | grep '<img src="http://imgs.xkcd.com/comics/' | sed s/title=\".*//g | sed 's/.png\"/.png/g' | sed 's/<img src=\"//g'`
--2010-08-24 18:20:34--  http://xkcd.com/
Resolving xkcd.com... 72.26.203.99
Connecting to xkcd.com|72.26.203.99|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7654 (7.5K) [text/html]
Saving to: ?STDOUT?

100%[=======================================================================================================================>] 7,654       --.-K/s   in 0.08s   

2010-08-24 18:20:34 (99.0 KB/s) - written to stdout [7654/7654]

Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
gwenview(13369)/kdeui (kdelibs): Attempt to use QAction "edit_redo" with KXMLGUIFactory! 
gwenview(13369)/kdeui (kdelibs): Attempt to use QAction "edit_undo" with KXMLGUIFactory! 
gwenview(13369)/kio (KIOJob) KIO::TransferJob::slotMimetype: mimetype() emitted again, or after sending first data!; job URL = KUrl("http://imgs.xkcd.com/comics/i_dont_want_directions.png") 
gwenview(13369)/kdecore (services) KMimeTypeFactory::parseMagic: Now parsing  "/usr/share/mime/magic"
gwenview(13369)/kdecore (services) KMimeTypeFactory::parseMagic: Now parsing  "/home/hunterm/.local/share/mime/magic"
gwenview(13369)/kdecore (KConfigSkeleton) KCoreConfigSkeleton::writeConfig:

-1
By: hunterm
2010-08-24 22:21:51

10 Alternatives + Submit Alt

  • This function displays the latest comic from xkcd.com. One of the best things about xkcd is the title text when you hover over the comic, so this function also displays that after you close the comic. To get a random xkcd comic, I also use the following: xkcdrandom(){ wget -qO- dynamic.xkcd.com/comic/random|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}


    24
    xkcd(){ wget -qO- http://xkcd.com/|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}
    eightmillion · 2009-11-27 09:11:47 11

  • 6
    eog `curl -s http://xkcd.com/ | sed -n 's/<h3>Image URL.*: \(.*\)<\/h3>/\1/p'`
    bluesman · 2010-08-31 13:23:21 0

  • 1
    wget `lynx --dump http://xkcd.com/|grep png`
    metalx1000 · 2009-12-03 23:10:22 0
  • I wasn't sure how to display the image, so I thought I'd try xml for a different twist. Show Sample Output


    0
    curl -s 'xkcd.com' | awk -F\" '/^<img/{printf("<?xml version=\"1.0\"?>\n<xkcd>\n<item>\n <title>%s</title>\n <comment>%s</comment>\n <image>%s</image>\n</item>\n</xkcd>\n", $6, $4, $2)}'
    putnamhill · 2009-12-03 19:49:37 0
  • This function displays the latest comic from xkcd.com. One of the best things about xkcd is the title text when you hover over the comic, so this function also displays that after you close the comic. To get a random xkcd comic use the following: xkcdrandom() { wget -qO- http://dynamic.xkcd.com/comic/random | sed -n 's#^<img src="\(http://imgs.[^"]\+\)"\s\+title="\(.\+\?\)"\salt.\+$#eog "\1"\necho '"'\2'#p" | bash; } These are just a bit shorter than the ones eigthmillion wrote, however his version didn't work as expected on my laptop for some reason (I got the title-tag first), so these build a command which is executed by bash.


    0
    xkcd() { wget -qO- http://xkcd.com/ | sed -n 's#^<img src="\(http://imgs.[^"]\+\)"\s\+title="\(.\+\?\)"\salt.\+$#eog "\1"\necho '"'\2'#p" | bash ; }
    John_W · 2010-08-25 15:44:31 3

What Others Think

The obligatory "don't parse HTML with regex" link: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
imgx64 · 582 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: