Skip to content

Instantly share code, notes, and snippets.

@schallis
Created December 30, 2010 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schallis/759659 to your computer and use it in GitHub Desktop.
Save schallis/759659 to your computer and use it in GitHub Desktop.
Grep through a \n terminated list of people and phone extensions
# Quick Bash function to lookup telephone extensions. Better if agrep is installed.
# Usage:
# $ tel steve
# 3900 - Steve Challis
# Terminal colour codes
export CYAN="\033[0;36m"
export GREEN="\033[0;32m"
PHONE_LIST='/usr/share/phone-extensions.txt'
tel() {
local NUMBER=$CYAN
local TEXT=$GREEN
if [ ! $1 ]
then
# Show all if no argument specified
cat $PHONE_LIST | less
else
# Use agrep if available
type -p agrep &>/dev/null && grepper="agrep -1" || grepper="grep"
echo -en "$TEXT"
echo -e "$grepper -i $* $PHONE_LIST |
egrep '^[^\*].*' |
sed 's/\([0-9]\{2,11\}x\{0,4\}\)/$NUMBER\1$TEXT/g'" |
bash -
echo -en "$NO_COLOUR"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment