I am trying to do a directory search using grep to find all words from a txt file. And I am not getting correct results ..can someone help me out ...below is my code..
#1/bin/sh
for word in `cat test.txt`
do
grep -ir "$word" /cygdrive/c/test /cygdrive/d/test1
case $? in
0) echo "$word" >> found.txt ;;
*) echo "$word" >> not_found.txt;;
esac
done
Lose the "-ir" on grep. In Linux the "-r" searches all files in the directory. The "-i" allows upper/lower case match. If the files you are searching actually contain whole lines which are identical to those in "test.txt", use "grep -x" for and exact match.
By the way there is a minor typo on the first line of the script.
A tip. Avoid creating files with the same name as a unix commands. A file called "test" is well known for upsetting shell "if" statements.
#/bin/sh
for word in `cat test.txt`
do
grep "$word" /cygdrive/c/test /cygdrive/d/test1
case $? in
0) echo "$word" >> found.txt ;;
*) echo "$word" >> not_found.txt;;
esac
done