Another grep advanced

﹥>﹥吖頭↗ 提交于 2020-01-06 05:40:31

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/10959666/another-grep-advanced

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!