I tried to come up with a Tcl script, but I'm looking for something in sed/awk commands to make this faster.
The file contains the following:
*Other text*
.....
.....
.....
SECTION LABELS {
lab M1 0 0 0 0 3 1 bot
lab M2 0 0 0 0 3 1 top
} SECTION LABELS
*Other text*
......
......
......
SECTION LABELS {
lab M1:NET 5207 12261 5207 12261 0 2 A
lab M2:NET 6880 5370 6880 5370 0 2 B
lab M1:NET 3454 5386 3454 5386 0 2 alpha
lab M2:NET 3454 5386 3454 5386 0 2 beta
} SECTION LABELS
I'm interested only in the lines containing within "SECTION LABELS". I'd like to:
- Change M1:NET to M1 and M2:NET to M2
- If the last element is A or B, change the number before A or B from 2 to 3
- If the last element is anything else, change the number (last but one) from 2 to 6
- If the numbers after lab M1:NET or lab M1 are 0 0 0 0, then I do not want to change anything.
- Rest of the contents of the file remain the same
So the output looks like:
*Other text*
.....
.....
.....
SECTION LABELS {
lab M1 0 0 0 0 3 1 bot
lab M2 0 0 0 0 3 1 top
} SECTION LABELS
*Other text*
......
......
......
SECTION LABELS {
lab M1 5207 12261 5207 12261 0 3 A
lab M2 6880 5370 6880 5370 0 3 B
lab M1 3454 5386 3454 5386 0 6 alpha
lab M2 3454 5386 3454 5386 0 6 beta
} SECTION LABELS