A simple text string search script
Sometimes you need to locate a text string in various configuration files. You don’t know which files. You can just use “grep
#!/bin/ksh
if [ -f /tmp/search.out ]
then
rm /tmp/search.out
touch /tmp/search.out
else
touch /tmp/search.out
fiecho -ne “Enter search string: ”
read STRif [ ! $STR ]
then
exit
fiecho -ne “Enter directory to search: ”
read DIRif [ $DIR ]
then
if [ ! -d "$DIR" ]
then
echo “$DIR does not exist”
exit
fi
else
exit
fii=1
find “$DIR” -type f -print | while read FILE
do
if [file $FILE | grep -c ASCII-eq 1 ]
then
clear
echo “Searching file ${i}: $FILE”
cat /tmp/search.out
if [fgrep -c "$STR" "$FILE"-gt 0 ]
then
echo “<$STR> found in $FILE” >> /tmp/search.out
fi
(( i = i + 1 ))
fi
doneclear
echo “Results in $i files in $DIR: ”
echo “————————————–”
if [ -f /tmp/search.out ]
then
more /tmp/search.out
else
echo “Nothing found.”
fi
-
Boo Cookie
-
Goe122
-
Rishi
-
Kevin
