Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • When I try this solution the output does not end at 'def' but goes to the end of the file 'blah' Commented Oct 25, 2019 at 14:43
  • 1
    maybe your grep does not support -P option Commented Oct 26, 2019 at 1:31
  • This was the only that worked for me - tried all sed suggestions, but didn't go as far as installing grep alternatives. Commented Oct 28, 2020 at 2:19
  • $ grep --version: grep (GNU grep) 3.1 in the Windows Git Bash has an option -P, --perl-regexp but (?s) doesn't seem to work there. It still shows the first line only. The same pattern with the same test string works on regex101.com. Is there an alternative in the Git Bash? sed? (sed (GNU sed) 4.8 here) Commented Nov 19, 2020 at 19:30
  • 3
    It is not the Perl -P which does the trick here, but the -z which lets grep operate on the entire input at once instead of line by line! Try grep -z 'abc.*def'. (Actually, it now operates on pieces separated by the zero-bytes, which is usually absent in text files.) Commented Sep 26, 2023 at 16:19