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>

Here's the query for 'linux' term:

$ dig +short txt
"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..."

We can simplify things, writing small script

dig +short txt "${1}"

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

COLUMNS=`tput cols`
dig +short txt "${1}" | 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

1 comment:

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