


Let's say your configuration file is called config.dat and it has standard format. The script itself simply prints any records matching the desired pattern. Then, the -ne means "Read each input record and apply the script given by -e to it".

The -00 tells perl to read the input file as paragraphs, so each record is a paragraph (defined by 2 consecutive \n characters) instead of a line. Personally, however, I would do this sort of thing using perl's paragraph mode: $ perl -00 -ne 'print if /yyyyyyyyy991/' file The regular expression looks for the word define, followed by 0 or more non- } characters ( *), then host_name yyyyyyyyy991 and then everything until the first } (. Interpret PATTERN as an extended regular expression (ERE, see below). Print only the matched (non-empty) parts of a matching line, with each null option, this option can be used with commands like sort -z to Zero byte (the ASCII NUL character) instead of a newline. Treat input and output data as sequences of lines, each terminated by a The grep options used are (from the man page of GNU grep): -z, -null-data Hostgroups +bu-automotiveprd,screen-automotiveprd2 If your grep supports it, you can use the -z option to make it slurp the entire file: $ grep -ozE 'define*host_name yyyyyyyyy991.+?}.' file
