# Multi-line text replacement with sed _Original question: "[Catch an entire function with grep](https://stackoverflow.com/questions/75220171/catch-an-entire-function-with-grep)" on Stack Overflow_ It _is_ possible to use (GNU) `grep` to do multiline matching[^fn1], but you're probably making more work for yourself that way, because `sed` can do basically everything `grep` can _plus_ make replacements. Using `grep -zoP` to do multiline matching is fundamentally the same trick as what's proposed below: turning your file into one long string, separated by non-printable ASCII characters. There are ways to accomplish this in other shells, but for convenience, I assume Bash or Z shell, for their [ANSI-C quoting][ansiq] and [command substitution][cmdsubst] features. The short answer is: ```bash SOH=$'\001' STX=$'\002' Ctrl+V, Ctrl+A or Ctrl+V, Ctrl+B. This is also how you enter a literal tab character in the terminal, since Tab normally triggers tab-completion: Ctrl+V, Tab or Ctrl+V, Ctrl+I. Do you see any [pattern][ascii] with the letters there? `;)` The ASCII `BEL` is a also fun character to use for tricks like this, because it sounds the terminal bell when printed, and it's very easy to type in Bash or Z shell. Try `printf \\a` and then refer to `man ascii` and `man printf` for why this works. The more you know! 🌠 [ansiq]: https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html [cmdsubst]: https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html [ascii]: https://www.man7.org/linux/man-pages/man7/ascii.7.html [regex]: https://www.man7.org/linux/man-pages/man7/regex.7.html [sedre]: https://man7.org/linux/man-pages/man1/sed.1.html#REGULAR_EXPRESSIONS [^fn1]: See [this Unix & Linux answer](https://unix.stackexchange.com/a/528158), for example.