I've got several large files that require some repetitive multiline search and 
replace operations, and I feel sure that sed can do this, but I can't figure 
out how to do it.

The pattern I'm searching for in the input file is "Type=0x21" followed by 
"Label=abcde" on the next line, where abcde is a 5 character number with 
leading spaces. If abcde is a multiple of 100, (d=0, e=0) I want to replace 
the first line with "Type=0x22", and add a third line "EndLevel=1"

For example:

BEFORE:                 AFTER:
Type=0x21               Type=0x21       # No change required because
Label=  120             Label=  120     # Label not multiple of 100
blah, blah              blah, blah

Type=0x21               Type=0x22       # Change Type value
Label=  100             Label=  100
blah, blah              EndLevel=1      # Insert extra line
                        blah, blah

Type=0x21               Type=0x22       # Same as previous except
Label= 2200             Label= 2200     # different value for Label
blah, blah              EndLevel=1
                        blah, blah

The bit that's got me stumped is how to handle the Label line. Can someone 
please give me hint how to do this?

Tom

Reply via email to