Skip to content

Instantly share code, notes, and snippets.

@kanru
Created February 9, 2012 08:57
Show Gist options
  • Save kanru/1778596 to your computer and use it in GitHub Desktop.
Save kanru/1778596 to your computer and use it in GitHub Desktop.
grep-id
#! /bin/sh
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This program uses id-utils[1] output as a hint for grep to quickly
# find the target term. Thus to use this program you have to create
# the ID database first.
#
# [1]: https://www.gnu.org/software/idutils/
INPUT=$1
HINT=$2
if [ x"$INPUT" = x"" ]; then
echo "Usage: grep-id term [hint]"
exit 1;
fi
if [ x"$HINT" != x"" ]; then
TERM="$HINT"
else
TERM="$INPUT"
fi
CAND=`lid -kpattern $TERM|cut -d' ' -f1 --complement`
if [ x"$CAND" != x"" ]; then
grep -i "$INPUT" $CAND
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment