皆さん、
行ごとに 1 つの文字列を持つ複数の行を含むテキスト ファイルがあります。
str1
str2
str3
等..
このファイルのすべての行を読み取り、別のディレクトリにある複数のファイル内でそれらの文字列を検索したいと思います。
進め方がよくわかりません。
どうもありがとうございました。
--file
オプションを使用するgrep(1) によると:
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file
contains zero patterns, and therefore matches nothing. (-f is
specified by POSIX.)
-H
およびフラグは-n
、各一致のファイル名と行番号を出力します。したがって、パターンを /tmp/foo に保存し、/tmp/bar 内のすべてのファイルを検索すると仮定すると、次のようなものを使用できます。
# Find regular files with GNU find and grep them all using a pattern
# file.
find /etc -type f -exec grep -Hnf /tmp/foo {} +
awk 'NR==FNR{a[$0];next} { for (word in a) if ($0 ~ word) print FILENAME, $0 }' fileOfWords /wherever/dir/*
while read -r str
do
echo "$str"
grep "$str" /path/to/other/files
done < inputfile