lines=open('GAUGE/L4GAUGE.CFG',encoding='latin-1').read().split('\n') depth=0; start=None for i,l in enumerate(lines[4900:5160],start=4901): for ch in l: if ch=='{': depth+=1 elif ch=='}': depth-=1 if i in (4901,4902,5127,5129,5146,5152) or depth==0 and i>4902 and start is None: pass # find Secondary1 block extent depth=0; opened=False; close=None for i,l in enumerate(lines,start=1): if i<4901: continue for ch in l: if ch=='{': depth+=1; opened=True elif ch=='}': depth-=1 if opened and depth==0: close=i; break print("Secondary1 block: 4901 ..", close, "| sectorDisplay@5146 inside:", 4901<=5146<=close) # what ports are in the block for i in range(4901,close+1): l=lines[i-1].strip() if l.startswith('port') or 'sectorDisplay' in l or l.endswith('overlay;'): print(f" {i}: {l}")