Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何获得GRIP考虑任何字符作为规则_Linux_String_Bash_Sed_Grep - Fatal编程技术网

Linux 如何获得GRIP考虑任何字符作为规则

Linux 如何获得GRIP考虑任何字符作为规则,linux,string,bash,sed,grep,Linux,String,Bash,Sed,Grep,我正在尝试grep脚本中的一些字符串。 我不知道我正在查找的字符串是什么,也不知道我在文件中试图查找它的位置是什么。我只需要文件中的grep精确的字符串 P> >我的问题是,有时Gring字符串包含方括号,正如我发现的,GRIP认为它们是特殊字符。 string='some [text]' grep "$string" file 我可以用sed逃离他们 string='some [text]' grep "$(sed -e 's/\[/\\[/g' <<< "$string

我正在尝试grep脚本中的一些字符串。 我不知道我正在查找的字符串是什么,也不知道我在文件中试图查找它的位置是什么。我只需要文件中的grep精确的字符串

<> P> >我的问题是,有时Gring字符串包含方括号,正如我发现的,GRIP认为它们是特殊字符。

string='some [text]'
grep "$string" file
我可以用sed逃离他们

string='some [text]'
grep "$(sed -e 's/\[/\\[/g' <<< "$string")" file
string='some[text]'

grep“$(sed-e's/\[/\\[/g'您可以使用
-F
选项将其解释为固定字符串:

grep -F "$string" file