bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#26726: Support grepping multi-lines fixed-strings


From: Jim Meyering
Subject: bug#26726: Support grepping multi-lines fixed-strings
Date: Mon, 1 May 2017 21:48:20 +0900

On Mon, May 1, 2017 at 3:38 PM, ziyunfei <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]