I'm trying to find a way to comment out a block (multiple lines) in a configuration file. I'd like to match the first line but also act on each line after that.sed '/\/Some\/Foo\/Bar\/String/' config.fileThe following example code is what I'm trying to match and comment out. The block will always end with a } but I also know the number of lines after the pattern match so this one would be pattern line + 6. foo { '/Some/Foo/Bar/String' :    key1 => value1,    key2 => value2,    key3 => value3,    key4 => value4,    key5 => value5,}Results after sed command#foo { '/Some/Foo/Bar/String' :#    key1 => value1,#    key2 => value2,#    key3 => value3,#    key4 => value4,#    key5 => value5,#}
sed match pattern and act on x lines after
sed
sed allows us to define ranges of lines and then apply substitutions only within those ranges.  We can define a range starting with a line containing Some/Foo/Bar/String and ending with a line containing } and then apply a substitute command to comment out those lines:$ sed '\|/Some/Foo/Bar/String|,/}/ s/^/#/' file#foo { '/Some/Foo/Bar/String' :#    key1 => value1,#    key2 => value2,#    key3 => value3,#    key4 => value4,#    key5 => value5,#}Details\|/Some/Foo/Bar/String|, /}/This defines the range.  It could have been written as /\/Some\/Foo\/Bar\/String/, /}/ but, to avoid backslashes, I used | as the delimiter in place of / for the first regex.s/^/#/This is applied only to lines in the range and it comments them out.