Skip to content

Instantly share code, notes, and snippets.

@schallis
Created December 30, 2010 10:29
Show Gist options
  • 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
PHONE_LIST='/usr/share/phone-extensions.txt'
tel() {
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 "$grepper -i $* $PHONE_LIST | egrep "^[^\*].*"" | bash -;
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment