43

有没有办法grep(或使用另一个命令)使用无正则表达式来查找确切的字符串?

例如,如果我想搜索(字面意思):

/some/file"that/has'lots\of"invalid"chars/and.triggers$(#2)[*~.old][3].html

我不想经历和逃避每一个“可以逃脱的”。本质上,我想通过它,就像我一样echo

$ echo "/some/file\"that/has'lots\of\"invalid\"chars/and.triggers$(#2)[*~.old][3].html"
/some/file"that/has'lots\of"invalid"chars/and.triggers$(#2)[*~.old][3].html
4

2 回答 2

68

使用fgrep, 与grep -F(匹配固定字符串) 相同。

于 2013-01-16T02:59:04.457 回答
16

好吧,您可以将要匹配的信息放在一行中,然后使用grep

grep -F -f patterns.txt file.txt

注意 flag 的使用-F,这导致将文件patterns.txtgrep的每一行视为要在file.txt中搜索的a 。fixed-string

于 2013-01-15T22:05:02.043 回答