lundi 23 mars 2015

sed match pattern and act on x lines after


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.file


The 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,
#}


Aucun commentaire:

Enregistrer un commentaire