On Mon, May 1, 2017 at 3:38 PM, ziyunfei <446240...@qq.com> wrote:
> I have the same need as 
> http://stackoverflow.com/questions/14631794/check-if-file-contains-some-text-not-regex-in-unix#comment20438757_14631832.
>
> $ cat file
> foo
> bar
>
> $ echo "$fixed_string"
> bar
> foo
>
> $ grep -Fzq "$fixed_string" file && echo "Matched" || echo "Not matched"
> Matched # false positive, -z doesn't apply to -F
>
>
> $ [[ "$(cat file)" = *"$fixed_string"* ]] && echo "Matched" || echo "not 
> matched"
> not matched # my workaround

Consider using perl, i.e., this matches:

   $ pat='foo
  bar'
  $ printf '%s\n' foo bar | perl -0 -ne 'm!\Q'"$pat"'\E! or die'

This does not match:

  $ printf '%s\n' bar foo | perl -0 -ne 'm!\Q'"$pat"'\E! or die'
  Died at -e line 1, <> chunk 1.



Reply via email to