grep supports it, you can use the
-z option to make it slurp the entire file:
$ grep -ozE 'define[^}]*host_name yyyyyyyyy991.+?}.' file
grep options used are (from the
man page of GNU
Treat input and output data as sequences of lines, each terminated by a
zero byte (the ASCII NUL character) instead of a newline. Like the -Z or
--null option, this option can be used with commands like sort -z to
process arbitrary file names.
Print only the matched (non-empty) parts of a matching line, with each
such part on a separate output line.
Interpret PATTERN as an extended regular expression (ERE, see below).
The regular expression looks for the word
define, followed by 0 or more non-
} characters (
host_name yyyyyyyyy991 and then everything until the first
.+?) plus the next character (the final
.) which will match the newline.
Personally, however, I would do this sort of thing using perl's paragraph mode:
$ perl -00 -ne 'print if /yyyyyyyyy991/' file
perl to read the input file as paragraphs, so each record is a paragraph (defined by 2 consecutive
\n characters) instead of a line. Then, the
-ne means "Read each input record and apply the script given by
-e to it". The script itself simply prints any records matching the desired pattern.