Sunday, September 23, 2012

Search inside text files

When we have many text files such as code samples or research documents then more often than not we want something which is in one of the files but we cannot remember which one. This is when searching inside text files becomes necessary. The great thing about the following script that I wrote is that it can search all sub-directories recursively.

I plan to add switches to ignore sub-directories and specific files in a later version.

# search inside text files : v2.0 by Jones

for i in `find . -type f -name "*"`
#echo $i
#cat "$i" | head -n 1

if [ "`cat $i | grep $1`" ] ; 
 echo "-------------------------------------" 
 echo "FILE : " $i 
 grep $1 $i -A2 -B2 --color=auto


No comments:

OK GOOGLE on Samsung Galaxy S7 doesn’t work

To make Ok Google detection work on Galaxy S7 (Galaxy series phones) we need to perform a couple of steps. 1. As long as Samsung S vo...