使用“grep -f"列出不匹配的条目 [英] Listing non matching entries using 'grep -f'

查看:41
本文介绍了使用“grep -f"列出不匹配的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令为我提供了匹配表达式的列表:

The following command gives me a list of matching expressions:

grep -f/tmp/list 文件名* >/tmp/输出

list 文件然后被解析并用于在Filename* 中搜索解析后的字符串.然后将结果保存到 output.

The list file is then parsed and used to search Filename* for the parsed string. The results are then saved to output.

如果 Filename* 中没有匹配项,我将如何从 list 输出解析后的字符串?

How would I output the parsed string from list in the case where there is no match in Filename*?

list 文件的内容可以是:

Contents of the list file could be:

ABC
BLA
ZZZ
HJK

示例文件:

Filename1:5,ABC,123
Filename2:5,ZZZ,342

运行命令的结果:

BLA
HJK

堆栈溢出问题 2480584 看起来可能是相关的,通过使用 if 语句.但是我不确定如何将解析后的字符串输出到输出文件.需要某种类型的读取线吗?

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,

麦克风

推荐答案

这使得它:

$ grep -v "$(cat Filename* | cut -d, -f2)" /tmp/list
BLA
HJK

说明

$ cat Filename* | cut -d, -f2
ABC
ZZZ

然后 grep -v 查找反向匹配.

And then grep -v looks for the inverse matching.

这篇关于使用“grep -f"列出不匹配的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆