write a find/replace script (in your fav lang) to do find replace all html files in a dir.
the script will be run in shell. it'll take 0 arg. (hardcode the input dir)
the input source is emacs 2.8 emacs lisp manual (html version, one page per node version. it's about 1k files. you can download it online.)
see which lang is fastest. (timing first run, and second run)
text pairs that we want to do find and replace.
Case matters
"Previous:" → "prev_ykzFQ"
"that" → "that_hM8xd"
"lambda" → "lam_cnj3G"
"number" → "num_j2CWg"
first run result, single file
(first run may include compile time, or loading executable to memory)
python3 : 0.17
go_compiled : 0.19
elisp : 0.39
go : 0.6
ruby : 1.28
WolframLang : 2.1
second run result, single file
go compiled : 0.04
python3 : 0.17
ruby : 0.18
elisp : 0.29
go : 0.57
WolframLang : 1.8
first run result, 1k files
go compiled : 3.5
python3 : 3.2
go : 3.7
ruby : 3.9
elisp : 5.4
WolframLang : 5.7
second run result, 1k files
go compiled : 0.5
ruby : 0.6
go : 1.0
elisp : 1.8
WolframLang : 2.6
python3 : 3.0
WolframLang
(* 2023-01-09 find replace multiple pairs in a dir *)(* code has a bug, of adding line return to the file *)
inputDir = "c:/Users/xah/xx/";
xpairs = {
"Previous:" -> "prev_ykzFQ",
"that" -> "that_hM8xd",
"lambda" -> "lam_cnj3G",
"number" -> "num_j2CWg"
};
Scan[
Module[{xold = ReadString[#], xnew},
xnew = StringReplace[xold, xpairs];
If[xold =!= xnew, WriteString[#, xnew]];
] &
,
FileNames["*html", inputDir, {1}] ]
Emacs Lisp
;; 2023-01-09 find and replace string of all files in a dir
(setqxinputDir"c:/Users/xah/xx/")
(setqxFindReplacePairs
[
["Previous:""prev_ykzFQ"]
["that""that_hM8xd"]
["lambda""lam_cnj3G"]
["number""num_j2CWg"]
])
(defun my-do-file (fPath)
"Process the file at path FPATH"
(let (($changed-pnil))
(with-temp-buffer
(insert-file-contents fPath)
(mapc
(lambda (x)
(let (($find (arefx 0)) ($rep (arefx 1)))
(goto-char 1)
(when (search-forward$findnilt)
(progn (replace-match$reptt) (setq$changed-pt)))
(while (search-forward$findnilt)
(replace-match$reptt))))
xFindReplacePairs)
(when$changed-p (write-region (point-min) (point-max) fPath)))))
(mapc #'my-do-file
(directory-filesxinputDirt"html$"t))