使用'grep -f'列出不匹配的条目 [英] Listing non matching entries using 'grep -f'
问题描述
下面的命令给了我一个匹配表达式的列表:
grep -f / tmp / list文件名*> / tmp / output
然后解析列表
文件并用于搜索 Filename *
分析字符串。然后将结果保存到 output
。
如何从输出解析的字符串,列表
在文件名*中没有匹配的情况下?
列表
文件的内容可以是:
ABC
BLA
ZZZ
HJK
示例文件:
文件名1:5, ABC,123
Filename2:5,ZZZ,342
运行命令的结果:
BLA
HJK
堆栈溢出问题 2480584 看起来可能相关,通过使用的if语句。不过,我不知道如何将解析的字符串输出到输出文件。需要一些类型的读取线?
TIA,
Mic
<解决方案
$ grep -v$ (cat Filename * | cut -d,-f2)/ tmp / list
BLA
HJK
说明
$ cat文件名* cut -d,-f2
ABC
ZZZ
然后 grep -v
寻找逆匹配。
The following command gives me a list of matching expressions:
grep -f /tmp/list Filename* > /tmp/output
The list
file is then parsed and used to search Filename*
for the parsed string. The results are then saved to output
.
How would I output the parsed string from list
in the case where there is no match in Filename*?
Contents of the list
file could be:
ABC
BLA
ZZZ
HJK
Example Files:
Filename1:5,ABC,123
Filename2:5,ZZZ,342
Result of Running Command:
BLA
HJK
Stack overflow question 2480584 looks like it may be relevant, through the use of an if statement. However I'm not sure how to output the parsed string to the output file. Would require some type of read line?
TIA,
Mic
This makes it:
$ grep -v "$(cat Filename* | cut -d, -f2)" /tmp/list
BLA
HJK
Explanation
$ cat Filename* | cut -d, -f2
ABC
ZZZ
And then grep -v
looks for the inverse matching.
这篇关于使用'grep -f'列出不匹配的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!