Files
aimsight-optimizer/sessions/NORDEND_2026-08-17T0515_2026-11-07T1400_20261118T1024Z/tools/replace.py
T

7 lines
306 B
Python
Raw Normal View History

# Replaces exactly one occurrence of OLD by NEW in FILE (fails if OLD is absent or not unique). Args: FILE OLD NEW
import sys
f, old, new = sys.argv[1:4]
s = open(f).read()
if s.count(old) != 1:
sys.exit(f"replace.py: {old!r} found {s.count(old)} times in {f}")
open(f, "w").write(s.replace(old, new))