gpt4 book ai didi

linux - grep 不作为正则表达式

转载 作者:IT老高 更新时间:2023-10-28 12:26:32 25 4
gpt4 key购买 nike

我需要搜索一个 PHP 变量 $someVar。但是,Grep 认为我正在尝试运行正则表达式并提示:

$ grep -ir "Something Here" * | grep $someVar
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
$ grep -ir "Something Here" * | grep "$someVar"
<<Here it returns all rows with "someVar", not only those with "$someVar">>

我没有看到告诉 grep not 将字符串解释为正则表达式的选项,而是将 $ 包含为另一个字符串字符。

最佳答案

使用 fgrep(已弃用)、grep -Fgrep --fixed-strings,使其将模式视为列表固定字符串,而不是正则表达式。

作为引用,文档提到(摘录):

-F --fixed-strings Interpret the pattern as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to be matched. (-F is specified by POSIX.)

fgrep is the same as grep -F. Direct invocation as fgrep is deprecated, but is provided to allow historical applications that rely on them to run unmodified.

如需完整引用,请查看: https://www.gnu.org/savannah-checkouts/gnu/grep/manual/grep.html

关于linux - grep 不作为正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9416390/

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