// node mut.mjs : replace exactly one occurrence, else exit 3. import { readFileSync, writeFileSync } from 'node:fs'; const [f, a, b] = process.argv.slice(2); const s = readFileSync(f, 'utf8'); const n = s.split(a).length - 1; if (n !== 1) { console.error(`matches=${n}`); process.exit(3); } writeFileSync(f, s.replace(a, () => b));