本文介绍了“grep | xargs grep“搜索条件不同的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想grep包含文本wp_但不包含文本wp3_的文件。例如。我有一个包含两个字符串的文件:

我尝试 $ grep -lr wp_〜/ tmp | xargs grep -vl wp3 _



它输出这个文件名!但是,如果我删除了换行符,它就像我想要的那样工作,即正确处理字符串wp_123 wp3_123。

如何使它适用于不同字符串的搜索条件? / p>

PS对不起有重复,但似乎没有人注意到在过去一小时内。

解决方案

$ c> $ grep -lr'wp_'〜/ tmp | xargs grep -L'wp3_'

在这种情况下,单引号不是必需的,但是很好习惯来防止模式字符被shell解释。在你最初的尝试中,-vl的意思是用至少一行不匹配的行打印每个文件。这里,-L表示打印每个文件时没有匹配的行。


I want to grep files that contain text "wp_" but do not contain text "wp3_". E.g. I've got a file with two strings:

I try $ grep -lr wp_ ~/tmp | xargs grep -vl wp3_

It outputs this file name! But if I remove the linebreak, it's working like I want, i.e. handles string "wp_123 wp3_123" correctly.

How to make it work with search conditions on different strings?

P.S. Sorry for kind of duplicate, but seems that nobody noticed my comment during last hour...

解决方案

This should work

$ grep -lr 'wp_' ~/tmp | xargs grep -L 'wp3_'

The single quotes are not necessary in this case, but are a good habit to prevent pattern characters from being interpreted by the shell. In your original attempt, -vl means "print each file with at least one line that does not match". Here, -L means "print each file with no lines that match".

这篇关于“grep | xargs grep“搜索条件不同的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:39