26 lines
960 B
Python
26 lines
960 B
Python
import re
|
|
|
|
input_file = "FeedLine.ini" # ÊäÈëÎļþÃû
|
|
output_file = "output_lineid2.txt" # Êä³öÎļþÃû£¨½ö°üº¬ lineid=2 µÄ Position ¿é£©
|
|
|
|
# ¶ÁÈ¡ÊäÈëÎļþ
|
|
with open(input_file, "r",encoding="utf-8") as f_in:
|
|
content = f_in.read()
|
|
|
|
# ÕýÔòÆ¥ÅäËùÓÐ [PositionX] ¿é
|
|
position_blocks = re.findall(r'(\[Position\d+\][\s\S]*?)(?=\n\[|\Z)', content)
|
|
|
|
# ɸѡ lineid = 2 µÄ¿é
|
|
filtered_blocks = []
|
|
for block in position_blocks:
|
|
if re.search(r'lineid\s*=\s*2\b', block): # Æ¥Åä "lineid = 2"£¨¼æÈݿոñ£©
|
|
filtered_blocks.append(block)
|
|
|
|
# дÈëÊä³öÎļþ
|
|
if filtered_blocks:
|
|
with open(output_file, "w",encoding="utf-8") as f_out:
|
|
f_out.write("\n\n".join(filtered_blocks))
|
|
print(f"? ³É¹¦ÌáÈ¡ {len(filtered_blocks)} ¸ö lineid=2 µÄ [PositionX] ¿é ¡ú {output_file}")
|
|
else:
|
|
print("? δÕÒµ½ lineid=2 µÄ [PositionX] Êý¾Ý£¡")
|