[英]Check if all lines from one file are present somewhere in another file
我使用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
你可以试试
awk -f a.awk file1 file2
a.awk
在哪里
BEGIN { IGNORECASE=1 }
NR==FNR {
a[$0]++
next
}
{
for (i in a)
if (index($0,i))
delete a[i]
}
END {
for (i in a)
print i
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.