Posts Tagged “Linux”

Here’s a script that I wrote to help me find things at work.


#!/bin/bash

if [ ! -n "$1" ]
then
echo "Usage: `basename $0` pattern [optional args to grep]"
echo "e.g. grepit findme -i"
echo
exit 1
fi

if [ ! -n "$2" ]
then
grep -r --exclude='*.log' "$1" * | grep -v '/\.svn/'
else
grep -r "$2" --exclude='*.log' "$1" * | grep -v '/\.svn/'
fi

Basically I just got tired of always specifying the recursive option to grep and having to exclude svn and log files (because they were redundant or took too long to search). I also found that sometimes I wanted to add additional arguments (like -i for ignoring case or -n for line numbers). So now when I change a function in one file and want to find every place that function was used I simply do a


grepit function_name

P.S. Let me know if you know a good way to strip leading whitespace from the results.

Tags: ,

Comments No Comments »

  •  

    March 2010
    M T W T F S S
    « Jan    
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
  • Archives

  • Support Virtual Kingdoms

  • Recent Comments