Monday, August 17, 2009

Searching wikipedia with dig (or host)

Dig is the tool to get information from DNS. As I read here, suprisingly, it can also be used to query wikipedia (english) from the command line. The syntax is:

dig +short txt <keyword>.wp.dg.cx

Here's the query for 'linux' term:

$ dig +short txt linux.wp.dg.cx
"Linux (commonly pronounced in English\; variants exist) is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration\; t" "ypically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the... http://a.vu/w:Linux"

We can simplify things, writing small script wiki.sh:

#!/bin/bash
dig +short txt "${1}.wp.dg.cx"

We can make the output prettier with this script (found here):

#!/bin/sh
COLUMNS=`tput cols`
dig +short txt "${1}".wp.dg.cx | sed -e 's/" "//g' -e 's/^"//g' -e 's/"$//g' -e 's/ http:/\n\nhttp:/' | fmt -w $COLUMNS

We can also use host command to do the same:

$ host -t txt linux.wp.dg.cx

1 comment:

  1. Nice Thanks for the sharing, although I prefer to using Firefox.

    ReplyDelete