Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要使用 egrep 在 shell 中查找并显示以 r 开头并以 g 结尾的行。
我有
egrep -e "^r*g$" testfile.txt
但它没有给我任何结果,我做错了什么?
添加一个.应该工作
.
egrep -e "^r.*g$"
它基本上意味着:以 ar 开头的所有内容,然后是零个或多个任何内容,然后以 g 结尾。
针对
r fsgdfs gfsdg fooo bar rfoo g fdsqfdsq rg
它返回
r fsgdfs gfsdg rfoo g rg
*是匹配的,r而不是“中间的任何东西”。将其更新为.*,您应该会看到结果:
*
r
.*
egrep -e "^r.*g$" testfile.txt