我有很多文件,每个文件都有多行内容,在大多数情况下,其中一行包含某种模式。我想列出每个没有包含这种模式的文件。
Grep返回0/1以指示是否有匹配,因此您可以执行以下操作:
for f in *.txt; do
if ! grep -q "some expression" $f; then
echo $f
fi
done
编辑:您也可以使用-L选项:
grep -L“某个表达式” *
grep -c [pattern] * | grep ':0$'
(如果您使用TurboGREP cough,您将没有-L开关;))
(编辑:在正则表达式的末尾添加“$”,以防文件名中有“:0”)
grep -lv 'expr' *
。 - amertune