I came across a page yesterday that contained a wikipedia script that allows
quick searches in wikipedia from the command line.  I saved the script but
could not find the site again this morning.  The script works fine.  I
simply changed the pager line to use /bin/share/less instead of more, so I
can scroll backwards if I choose.

Usage:
$ ./wikipedia.sh "Avogadro's number"       <--- an apostrophe is a special
character, so use quotes
$ ./wikipedia.sh Avogadro number
$ ./wikipedia.sh Avogadro




#!/bin/bash

#
# wikipedia.sh - Forget the regular encyclopedia
#
# 2008 - Mike Golvach - [email protected]
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States
License
#

numargs=$#

if [ $numargs -lt 1 ]
then
echo "Usage: $0 Your Wikipedia Query"
echo "Ex: $0 linux"
echo "Ex: $0 \"linux kernel"
echo "Quotes only necessary if you use apostrophes, etc"
exit 1
fi

if [ $numargs -gt 1 ]
then
args=`echo $args|sed 's/ /_/g'`
fi

echo

args="$@"
wget=/usr/bin/wget
pager=/usr/bin/less

$wget -nv -O - "http://en.wikipedia.org/wiki/${args}"; 2>&1|grep -i
"Wikipedia does not have an article with this exact name" >/dev/null 2>&1

anygood=$?

if [ $anygood -eq 0 ]
then
args=`echo $args|sed 's/%20/ /g'`
echo "No results found for $args"
exit 2
fi

$wget -nv -O - "http://en.wikipedia.org/wiki/${args}"; 2>&1|sed -e :a -e
's/<[^>]*>/ /g;/</N;//ba'|sed -e '1,/Jump to:/d' -e '/^$/N;/\n$/N;//D' -e
'/^.*[.*edit.*].*See also.*$/,$d' -e '/This *disambiguation *page/,$d' -e
'/^$/N;/\n$/D'|$pager

exit 0

--~--~---------~--~----~------------~-------~--~----~
Central West End Linux Users Group (via Google Groups)
Main page: http://www.cwelug.org
To post: [email protected]
To subscribe: [email protected]
To unsubscribe: [email protected]
More options: http://groups.google.com/group/cwelug
-~----------~----~----~----~------~----~------~--~---

Reply via email to