Grep:如何 grep 查找包含冒号的字符串

发布于 2025-01-13 09:37:48 字数 434 浏览 2 评论 0原文

我想 grep 查找以冒号 : 开头的字符串,其中包含 0 个或多个字符,然后以字符串 mystring 结尾。

我尝试了这个: grep -rI ':*mystring' . 但这不起作用。

通过搜索,我认为这不起作用的原因是因为它匹配“0个或多个冒号字符 : 的实例,后跟 mystring。(查看这个问题的答案

这对我来说没有多大意义,因此我的 。

编辑: 无 链接问题中的答案解决了这个问题,没有提到匹配冒号字符,并且尝试调整答案也不起作用。

I want to grep for a string which begins with a colon :, the contains 0 or more characters of anything, and then ends with the string mystring.

I tried this: grep -rI ':*mystring' . but this did not work.

From searching, I believe the reason this does not work is because it is matching "0 or more instances of the colon character : followed by mystring. (See an answer on this question)

That doesn't make much sense to me, hence my question.

Edit: None of the answers in the linked question solve this problem. There is no mention of matching a colon character, and trying to adapt the answers does not work either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

dawn曙光 2025-01-20 09:37:48

您可以使用

grep -rI '^:.*mystring' file

详细信息

  • ^ - 字符串开头
  • : - 冒号
  • .* - 任何零个或多个字符
  • mystring - 一个字符串。

You can use

grep -rI '^:.*mystring' file

Details:

  • ^ - start of string
  • : - a colon
  • .* - any zero or more chars
  • mystring - a string.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文