Findme
From Attie's Wiki
(Difference between revisions)
m (Created page with 'This is a nice little script that will recursively search the current directory for a string The <code>search_string</code> and <code>file_mask</code> use regex... you have been…') |
m |
||
(One intermediate revision by one user not shown) | |||
Line 13: | Line 13: | ||
MYMASK=. | MYMASK=. | ||
fi | fi | ||
− | find . -type f -not -path | + | find . -type f -not -path '*/.svn*' -not -path '*/.git*' -printf "%p\n" | while read f; do |
− | if [ ! " | + | if [ ! "$(echo "$f" | grep -E -- "$MYMASK")" = "" ]; then |
− | if [ ! " | + | if [ ! "$(cat "$f" | grep -i -E -- "$1")" = "" ] ; then |
− | + | echo -e "\0033[93m$f\0033[0m" | |
− | + | grep -inTE -C2 --color=always -- "$1" "$f" | |
− | + | echo -en "\0033[94m" | |
− | + | echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" | |
− | + | echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" | |
− | + | echo -e "\0033[0m" | |
− | + | ||
− | + | ||
fi; | fi; | ||
fi; | fi; |
Latest revision as of 18:19, 27 September 2012
This is a nice little script that will recursively search the current directory for a string
The search_string
and file_mask
use regex... you have been warned :)
#!/bin/bash if [ "$1" = "" ]; then echo "Usage: $0 <search_string> [file_mask]"; else if [ ! "$2" = "" ]; then MYMASK=$2 else MYMASK=. fi find . -type f -not -path '*/.svn*' -not -path '*/.git*' -printf "%p\n" | while read f; do if [ ! "$(echo "$f" | grep -E -- "$MYMASK")" = "" ]; then if [ ! "$(cat "$f" | grep -i -E -- "$1")" = "" ] ; then echo -e "\0033[93m$f\0033[0m" grep -inTE -C2 --color=always -- "$1" "$f" echo -en "\0033[94m" echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo -e "\0033[0m" fi; fi; done; fi