Created
December 30, 2010 10:29
-
-
Save schallis/759659 to your computer and use it in GitHub Desktop.
Grep through a \n terminated list of people and phone extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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