Finding a list of files by name given a list of keywords and finding the list of keywords that were not found
The problem: I have a list of keywords like this in file call keywords.txt
141367
141374
141376
141368
and I need to use it to search a large complex folder for any file with any of the keywords in its name. I need a rep开发者_运维问答ort of two different lists.
- The list of files found that contains any of the keywords in its name.
- The list of keywords that were never found in any file name.
Help?
untested
files=$(find folder_name -type f | fgrep -f keywords.txt)
not_found=$(comm -23 <(sort keywords.txt) <(fgrep -f keywords.txt <<< "$files" | sort)
Here's something in bash
(ver4+)
#!/bin/bash
filecontent=($(<file))
shopt -s globstar
for file in **
do
found="0"
for word in ${filecontent[@]}
do
case "${file##*/}" in
*"$word"* )
echo "file found: $file with keyword: $w"
found="1"
;;
esac
done
case "$found" in
"0") echo "No keyword file: $file";;
esac
done
精彩评论