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.



#!/bin/bash
# search inside text files : v2.0 by Jones

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


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

done


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...