GNU bug report logs - #26726
Support grepping multi-lines fixed-strings

Previous Next

Package: grep;

Reported by: "ziyunfei" <446240525 <at> qq.com>

Date: Mon, 1 May 2017 06:54:01 UTC

Severity: wishlist

Full log


Message #8 received at 26726 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: ziyunfei <446240525 <at> qq.com>
Cc: 26726 <at> debbugs.gnu.org
Subject: Re: 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 <446240525 <at> 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.




This bug report was last modified 7 years and 362 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.