Linux搜索字符串在带有空间的文件中

发布于 2025-01-25 22:11:14 字数 169 浏览 3 评论 0原文

我试图弄清楚如何在Linux中搜索字符串,希望有人可以帮助我。

grep "Test\|Account" test.txt

如果我只想搜索一个单词,则上述命令有效。 但是,当我尝试搜索“创建测试'帐户'”时,不确定如何使用GREP,因为我是Linux中的新手。

Im trying to figure out how to search a string in Linux i hope someone can help me out.

grep "Test\|Account" test.txt

The above command works if i only want to search for one word.
But when i try to search "Create Test 'account'" not sure how to use grep since im a newbie in Linux.

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

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

发布评论

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

评论(1

凝望流年 2025-02-01 22:11:14

使用GNU GREP,您可以

grep "Create Test 'account'\|Create Test \`account\`" test.txt

在此处使用,因为它们在评估它们的双引号字符串中被使用,因此将其逃脱。 | REGEX交替操作员被逃脱了,因为它被认为是字面的管子char。

详细信息

  • 创建测试'帐户' - 字面文本
  • \ | - 或
  • 创建test test`earcepor` a字面文字

With a GNU grep, you can use

grep "Create Test 'account'\|Create Test \`account\`" test.txt

Here, the backticks are escaped since they are used inside a double quoted string where they are evaluated. The | regex alternation operator is escaped because it is considered a literal pipe char otherwise.

Details:

  • Create Test 'account' - a literal text
  • \| - or
  • Create Test `account` - a literal text
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文