searching for a string in a directory hierarchy

Much of the puppet infrastructure I work with is unmapped – it is the result of tickets submitted and variables asked for by developers or placed as solutions. This exists above the structure we designed and created intentionally.

To discover where a variable is set in puppet, often I search through the entire puppet working space checked out from svn for the variable string, and then again to find where that variable is set. This command lets me find the patterns that map those threads – say where a camel setting was made as the application was developed and then moved into puppet management.

for i in `du -ak | egrep -v \.svn | awk '{ print $2 }'`
do
if [[ `grep -i camel $i | grep -i master` ]]; then
echo ""
echo __________________________________________
echo $i
echo __________________________________________
grep -i camel $i | grep -i master; echo ""
fi
done

Using UNIX pipes, grab a listing of files and then search for a specific string within each file, displaying the results in a way that allows you to pick out patterns and map variables and strings.
This makes the output readable, and is a copy-and-paste I wind up using constantly to debug or work through where a puppet setting went wrong.

–doug