【发布时间】:2020-03-03 14:12:12
【问题描述】:
我正在尝试查找在该行的第一个句点之前包含字母 a 的所有行。
这是一个示例文件:
test123a.hello
example.more-test-a.xyz
stacka.tester.this
nothing.nothing.nothing
在上面的例子中,我想grep这两行:
test123a.hello
stacka.tester.this
这是我尝试过的:
grep ".*a\." test.txt
这得到了我想要的 2 行,但它也得到了我不想要的这一行,因为 a 在第二个句号前面,而不是第一个句号:
example.more-test-a.xyz
如何将其限制为仅在第一个句点之前获取带有a 的行?
【问题讨论】:
标签: regex linux shell command-line grep