I hope somebody would be able to help me.
I would need to search a string coming from a file, example file.txt:
dog
cat
goat
horse
fish
For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.
And then should be able to create a status report file based from the result of the search, and produce the following format:
report.txt
As with all shell scripting questions: which shell (and version) do you use? Which OS (and version) do you use? And, most important of all: what have you tried already?
Hi! It is an Oracle Linux Server 7.1.
I have tried the usual grep commands I can search in the site, but I have yet to see a mechanism that reads a file for strings (probably should be done using a loop) and find it recursively in a directory then prints a status.
I am still searching though.
Thanks!
Hi RudiC
I tried through "tee" output to the stderr, hence the my first varient with "cut", but I did not succeed.
I will write your code in my notes. Thanks
Else this awk approach might work, but - like all other proposals above - it needs to exclude file.txt from being looked into for matches. This can be achieved by either having it in a different directory path, or by applying "extended pattern matching" with the extglob shell option set ( man bash ). Try
$ shopt -s extglob
$ awk 'FNR == NR {T[$1]; next} {for (t in T) if ($0 ~ t) T[t] = 1} END {for (t in T) print t (T[t]?"|found":"|missing")}' file.txt !(file.txt)