我使用 file1
作为 file2
的数据源,现在我需要确保 file1
中的每一行文本都出现file2
中的某处(并找出缺少的行,如果有的话)。可能需要注意的是,虽然 file1
每行有一个搜索词,但这些词可以出现在 file2
中的任何地方,包括在一个字。如果匹配不区分大小写,这也会有所帮助 - 只要 file2
中的文本是否全部大写都无所谓。
file1
中的行包括空格和各种其他特殊字符,如 --
。
最佳答案
if grep -Fqvf file2 file1; then
echo $"There are lines in file1 that don’t occur in file2."
fi
Grep 选项意味着:
-F, --fixed-strings PATTERN is a set of newline-separated fixed strings
-f, --file=FILE obtain PATTERN from FILE
-v, --invert-match select non-matching lines
-q, --quiet, --silent suppress all normal output
关于linux - 检查一个文件中的所有行是否都存在于另一个文件中的某处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20888903/