Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何使用grep过滤管道信息,并在找到单词时过滤所有信息_Linux_Bash_Grep - Fatal编程技术网

Linux 如何使用grep过滤管道信息,并在找到单词时过滤所有信息

Linux 如何使用grep过滤管道信息,并在找到单词时过滤所有信息,linux,bash,grep,Linux,Bash,Grep,我想通过管道连接到grep,如果找到了这个词,我会像这样忽略整个块 command | grep -v nothing && echo "disregarded block" || (echo the entire block of data) 所有这些都在一个bash文件中 任何建议???如果命令没有输出任何NUL字符,使用GNUgrep(通常在许多围绕Linux内核构建的系统上都可以找到),您可以执行以下操作: buf=$(tmpfile) command > $bu

我想通过管道连接到grep,如果找到了这个词,我会像这样忽略整个块

command | grep -v nothing && echo "disregarded block" || (echo the entire block of data)
所有这些都在一个bash文件中


任何建议???

如果命令没有输出任何NUL字符,使用GNU
grep
(通常在许多围绕Linux内核构建的系统上都可以找到),您可以执行以下操作:

buf=$(tmpfile)
command > $buf
if grep -vq "nothing" $buf; then echo 'disregarded block'; else cat $buf; fi
unlink $buf
command | grep -zv nothing

最好给出示例数据以及您希望从中获得的信息。