gpt4 book ai didi

grep - grep 可以只显示与搜索模式匹配的单词吗?

转载 作者:行者123 更新时间:2023-12-03 03:53:42 27 4
gpt4 key购买 nike

有没有办法让 grep 从与搜索表达式匹配的文件中输出“单词”?

如果我想在多个文件中查找“th”的所有实例,我可以这样做:

grep "th" *

但是输出会是这样的(粗体是我写的);

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

使用 grep 可以吗?或者使用其他工具组合?

最佳答案

尝试grep -o:

grep -oh "\w*th\w*" *

编辑:与菲尔的评论相匹配。

来自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 - grep 可以只显示与搜索模式匹配的单词吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1546711/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com