另一个grep先进 [英] Another grep advanced

查看:167
本文介绍了另一个grep先进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Q1。我想grep类似的东西:

  grep -Ir --exclude-dir =some * dirsmy-text 〜/ somewhere 

但我不想显示包含my-text ,我想只看到文件列表。



Q2。我想查看包含my-text但不包含another-text的文件列表。如何做到这一点?



对不起,我找不到grep中的答案,在google中也没有。

解决方案

Q1。你一定不会在这个搜索引擎上搜索得很困难。

man grep


- l, - 文件与匹配

抑制正常输出;而是输出通常打印输出的每个输入
文件的名称。
扫描将在第一场比赛中停止。


Q2。除非你期望两种模式在同一行,否则你需要多次调用grep。例如:

  $ grep -l my-text | xargs grep -vl another-text 


Q1. I want to grep something like that:

grep -Ir --exclude-dir="some*dirs" "my-text" ~/somewhere

but I don't want to show the whole strings containing "my-text", I want to see only list of files.

Q2. I want to see list of files containing "my-text" but not containing "another-text". How to do that?

Sorry, but I could not find the answer in man grep, neither in google.

解决方案

Q1. You mustn't have googled very hard on that one.

man grep

-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.

Q2. Unless you expect both patterns to be on the same line, you'll need multiple invocations of grep. Something like:

$ grep -l my-text | xargs grep -vl another-text

这篇关于另一个grep先进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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