在Unix中检查文件是否包含一些文本(非正则表达式)

use*_*166 6 unix grep

我想检查多行文本是否与输入匹配。grep接近,但我找不到方法将其解释为纯文本而不是正则表达式。

仅使用Unix实用程序怎么做?

Ant*_*nko 6

用途grep -F

-F, --fixed-strings

将PATTERN解释为由换行符分隔的固定字符串列表,其中任何一个都将被匹配。(-F由POSIX指定。)

编辑:最初我对这个问题不太了解。如果模式本身包含换行符,请使用-z选项:

   -z, --null-data
          Treat  the  input  as  a set of lines, each terminated by a zero
          byte (the ASCII NUL character) instead of a newline.   Like  the
          -Z  or --null option, this option can be used with commands like
          sort -z to process arbitrary file names.
Run Code Online (Sandbox Code Playgroud)

我已经测试过,多行模式有效。


小智 1

man grep

-F, --fixed-strings
       Interpret  PATTERN  as  a  list  of  fixed strings, separated by
       newlines, any of which is to be matched.  (-F  is  specified  by
       POSIX.)
Run Code Online (Sandbox Code Playgroud)