search
top

How to search for a string within files (recursively)

#!/bin/sh
#
# Script to search recursively for a string in the current directory
#
 
if [ "" == $1 ]
        then
        echo "Please specify a string to search for."
 
else
        grep -ril $1 .
 
fi

If you want to look for a string in specific files, you can do the following:

#!/bin/sh
#
# Script to search recursively for a string in the current directory
#
find . -type f -name $1 -exec grep -rilo $2 {} \;

grep:
-r = recursive
-i = ignore case distinctions
-l = only print FILE names containing matches
-o = show only the part of a line matching PATTERN

VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

top