私は.txt
多くのファイルが含まれているフォルダにあり、含まれているがstringA
含まれていないすべてのファイルを探したいと思いますstringB
(同じ行にある必要はありません)。これを行う方法を知っている人はいますか?
ベストアンサー1
ファイル名にスペース、タブ、改行(変更されていないと仮定$IFS
)、またはワイルドカードが含まれていないで始まらない限り、そのオプションをサポートしている-
場合は、次のようにできます。grep
-L
$ cat file1
stringA
stringC
$ cat file2
stringA
stringB
$ grep -L stringB $(grep -l stringA file?)
file1
grep
サブシェルで実行すると、$()
すべてのインクルードが印刷されますstringA
。ファイルリストは、grep
すべてのインクルードがリストされていない基本コマンドへの入力ですstringB
。
~からman grep
-v, --invert-match
Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
-L, --files-without-match
Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)