start = "\xf8"
finish = "\r"

with open('megasport_new_5.txt', 'r') as file:
    new_lines = []
    current_line = ""
    capturing = False

    for line in file:
        if start in line:
            capturing = True
            current_line = line[line.index(start):]
        elif capturing:
            if finish in line:
                finish_idx = line.index(finish)
                current_line += line[:finish_idx + len(finish)]
                new_lines.append(current_line)
                current_line = ""
                capturing = False
            else:
                current_line += line

with open('new_log.txt', 'w') as new_file:
    for line in new_lines:
        new_file.write(line + '\n')
