grep只能显示匹配搜索模式的文字吗? [英] Can grep show only words that match search pattern?
本文介绍了grep只能显示匹配搜索模式的文字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以从符合搜索表达式的文件中生成grep输出words?
如果我想查找所有我可以这样做:
grepth*
但输出结果类似于(大胆的是我);
some-text-file: 猫坐在 垫上
some-other-text-file: quick brown fox
yet-another-text-file:我希望这个彻底解释
使用相同的搜索,我希望它输出的是:
$ $ $ $ $ $ $ $ $ $
$ b this
彻底
这可能吗?使用grep?或者使用其他工具组合?
解决方案
尝试grep -o
grep -oh\w * th\w **
编辑:与Phil的评论匹配
从 docs :
-h,--no-filename
抑制输出上文件名的前缀。当只有一个文件(或只有标准输入)要搜索时,这是默认的
。
-o, - 仅匹配
在一个单独的输出行上仅打印匹配行的匹配(非空)部分,
与每个这样的部分。
Is there a way to make grep output "words" from files that match the search expression?
If I want to find all the instances of, say, "th" in a number of files, I can do:
grep "th" *
but the output will be something like (bold is by me);
some-text-file : the cat sat on the mat some-other-text-file : the quick brown fox yet-another-text-file : i hope this explains it thoroughly
What I want it to output, using the same search, is:
the
the
the
this
thoroughly
Is this possible using grep? Or using another combination of tools?
解决方案
Try grep -o
grep -oh "\w*th\w*" *
Edit: matching from Phil's comment
From the docs:
-h, --no-filename
Suppress the prefixing of file names on output. This is the default
when there is only one file (or only standard input) to search.
-o, --only-matching
Print only the matched (non-empty) parts of a matching line,
with each such part on a separate output line.
这篇关于grep只能显示匹配搜索模式的文字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文