Page 1 of 1

RegEx/sed help

PostPosted: Sun Apr 22, 2012 11:53 am
by eGRes5
Trying to parse and replace specific entries but having some trouble with this. I know of another way to do this but its hackish and doesn't help me in the long run(removing [###] and inserting needed sequence every 8 lines - so don't suggest it)

Basically I have a file with these contents:
Code: Select all
[99]

TriggerTop    = [Monitor2Top]  + ([Monitor2Height] / 10 * 1)
TriggerBottom = [Monitor2Top]  + ([Monitor2Height] / 10 * 2)
TriggerLeft   = [Monitor2Left] + ([Monitor2Width]  / 10 * 8)
TriggerRight  = [Monitor2Left] + ([Monitor2Width]  / 10 * 9)
GridTop       = [Monitor2Top]
GridBottom    = [Monitor2Top] + ([Monitor2Height] /2)
GridLeft      = [Monitor2Right] - ([Monitor2Width] /2)
GridRight     = [Monitor2Right]


[100]

TriggerTop    = [Monitor2Top]  + ([Monitor2Height] / 10 * 1)
TriggerBottom = [Monitor2Top]  + ([Monitor2Height] / 10 * 2)
TriggerLeft   = [Monitor2Left] + ([Monitor2Width]  / 10 * 7)
TriggerRight  = [Monitor2Left] + ([Monitor2Width]  / 10 * 8)
GridTop       = [Monitor2Top]
GridBottom    = [Monitor2Top] + ([Monitor2Height] /2)
GridLeft      = [Monitor2Right] - ([Monitor2Width] /3*2)
GridRight     = [Monitor2Right]


[101]

TriggerTop    = [Monitor2Top]  + ([Monitor2Height] / 10 * 2)
TriggerBottom = [Monitor2Top]  + ([Monitor2Height] / 10 * 3)
TriggerLeft   = [Monitor2Left] + ([Monitor2Width]  / 10 * 9)
TriggerRight  = [Monitor2Left] + ([Monitor2Width]  / 10 * 10)
GridTop       = [Monitor2Top]
GridBottom    = [Monitor2Top] + ([Monitor2Height] /3*2)
GridLeft      = [Monitor2Right] - ([Monitor2Width] /3)
GridRight     = [Monitor2Right]


But I'm trying to append entries like these but I need to modify the lines starting with [##] and [###] so that they start at 333 and go upwards. e.g.
[333]
[334]
[335]

So far I think I can use "seq 333 444" in a for loop but can't figure out how to insert the 8 trailing lines in the right order.
I also found the regex to match the needed lines: /^[.*.\]

I think I might be able to do this using sed alone but no luck so far.