Skip to content

Instantly share code, notes, and snippets.

@rdp
Created December 3, 2018 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdp/0286d91624930bd11d0169d6a6337c33 to your computer and use it in GitHub Desktop.
Save rdp/0286d91624930bd11d0169d6a6337c33 to your computer and use it in GitHub Desktop.
grep multiline perl test
$ cat ~/example.html
not it
<title>
yess 1
2
</title>
$ grep -P '(?s)<title>.*</title>' ~/example.html
$
@rdp
Copy link
Author

rdp commented Dec 3, 2018

$ grep --version
GNU grep 2.6.3

Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

@rdp
Copy link
Author

rdp commented Jan 20, 2022

$ grep -Pz '(?s)<title>.*</title>' ~/example.html
not it

<title> yess 1 2 </title>

Just beware -z adds a trailing NUL char to the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment