Tuesday, April 5, 2011

HOWTO - BASH Dictionary using Google

For me Linux console is more easier to access than the Google.com on browser everytime. Even though Google.com's "define:xyz" has always been a priority selection to see definitions of words and phrases, I thought of bringing that power of google into my linux console. Not for others, but atleast for myself. :)

Here is a small script on Bash (#!/bin/bash), to do a quick lookup of words into dictionary. I created an executable. Moved it into /usr/local/bin/define



And its how I use this command

acpmasquerade@makooza:~$ define programming
DEFINE: programming

========================================
* scheduling: setting an order and time for planned events
* creating a sequence of instructions to enable the computer to do
something
wordnetweb.princeton.edu/perl/webwn
* Computer programming (often shortened to programming or coding) is the
process of writing, testing, debugging/troubleshooting, and maintaining
the source code of computer programs. This source code is written in a
programming language. ...
en.wikipedia.org/wiki/ProgramMing
* Programming is a form of music production and performance using
electronic devices, often sequencers or computer programs, to generate
music. Programming is used in nearly all forms of electronic music and in
most hip hop music since the 1990s. ...
en.wikipedia.org/wiki/Programming_(music)
* The designing, scheduling or planning of a radio or television program /
programme; brain-washing; : The act of writing a computer program; The
software that controls a machine, or the logic or expressed in such
software; operating instructions
en.wiktionary.org/wiki/programming
* program - plan: a series of steps to be carried out or goals to be
accomplished; "they drew up a six-step plan"; "they
discussed plans for a new bond issue"
* program - a system of projects or services intended to meet a public
need; "he proposed an elaborate program of public works";
* program - broadcast: a radio or television show; "did you see his
program last night?"
* program - platform: a document stating the aims and principles of a
political party; "their candidate simply ignored the party
platform"; "they won the election even though they offered no
positive program"
========================================
@acpmasquerade :)




#!/bin/bash
# A quick dictionary
# based upon Google's define: keyword for search
# @author acpmasquerade
######################################################
word=$1
user_agent="Lynx (textmode)"
echo "DEFINE: $word"
echo ""
google=`curl "http://www.google.com/search?hl=en&q=define%3A${word}" --user-agent "${user_agent}" --silent`
echo "========================================"
result=`echo ${google} | html2text | grep -i "^ \{4\}[\*\| ] \w" | head -30`
result=`php -r 'echo htmlspecialchars_decode($argv[1]);' "$result"`
if [[ "$result" ]]
then
        echo "$result"
else
        echo "No results found"
fi
echo "========================================"
echo "@acpmasquerade :)"



Dependencies
Its not a pretty bash only script. Since my laptop has php, and html2text, I didn't bother on how to HTML-to-Text and how to htmlspecialchars_decode :)

1 comment:

  1. It requires some changes now.
    Google has changed the dictionary page

    ReplyDelete