I have a directory with 2000+ text files. I am trying to make a script that:
- Reads a list of IP addresses from
ip.txt - Cats each file in the directory
- Greps each file for the IP address
If keyword is found, echoes the keyword and the file name to a file.
The output should be like this:
$ cat
results.txt
192.168.2.3 was found in 23233.txt
192.168.4.0 was found in 2323.txt
At the moment I have this:
while read p; do
for filename in *.txt; do
if cat $filename | grep "$p"
then echo "$p" is "$filename" | tee result.txt
fi
done
done<ips.txt
However this also echoes all file names into the results. How can I fix this?