Substitute all occurrences of strings with their replacements. Substitution pairs are read from a TSV file.
subf <replacements.tsv> <input.txt>The result is printed to stdout.
The replacements file is a TSV (tab-separated values) file where each line contains a match and its replacement, separated by a tab:
value replacement
broken correct- Lines starting with
#are treated as comments. - Matches are case-insensitive and respect word boundaries,
so
valwon't match insidevaluable. - Replacements starting with
\uare interpreted as Unicode code points (e.g.\u0041becomesA).
Given replacements.tsv:
val replacement
broken correctAnd example.txt:
val
val
another val
valuable
Broken
BROKEN
it is broken
Running subf replacements.tsv example.txt outputs:
replacement
replacement
another replacement
valuable
correct
correct
it is correct
npm install subfSubf can also be used as a library:
import { searchAndReplace } from "subf"
const result = await searchAndReplace("replacements.tsv", "input.txt")A Nix flake is provided for reproducible setup:
nix developCheck out the makefile for available commands.