def remLines(infilepath, outfilepath, delim, above, below):
infile = open(infilepath)
outfile = open(outfilepath, 'w')
buff = []
line = infile.readline()
while line:
if line.strip() == delim:
buff = []
for _ in range(below): # need to error check here, if you're not certain that your input file is correctly formatted
infile.readline()
else:
if len(buff) == above:
outfile.write(buff[0])
buff = buff[1:]
buff.append(line)
line = infile.readline()
outfile.write(''.join(buff))
if __name__ == "__main__":
remLines('path/to/input', 'path/to/output', "Position fix ind: 0", 6,3)
Testing:
Input:
1
2
3
*--------------------------------------*
UTC Time: 000000.00
Latitude: 0000.0000
N/S ind.: N
Longitude: 0000.0000
E/W ind: E
Position fix ind: 0
Satellites Used: 3
MSL Altitude: 00.0
*--------------------------------------*
3
2
1
1
2
3
*--------------------------------------*
UTC Time: 000000.00
Latitude: 0000.0000
N/S ind.: N
Longitude: 0000.0000
E/W ind: E
Position fix ind: 5
Satellites Used: 3
MSL Altitude: 00.0
*--------------------------------------*
3
2
1
Output:
1
2
3
3
2
1
1
2
3
*--------------------------------------*
UTC Time: 000000.00
Latitude: 0000.0000
N/S ind.: N
Longitude: 0000.0000
E/W ind: E
Position fix ind: 5
Satellites Used: 3
MSL Altitude: 00.0
*--------------------------------------*
3
2
1