Xah Talk Show 2021-10-15 grep/sed find/replace in WolframLang elisp golang python perl PowerShell
- demo find replace in elisp Emacs: Xah Find Replace (xah-find.el)
- demo in powershell
- Golang: Script to Find Replace Multi-Pairs of Regex in a Directory
- Python: Find Replace Regex in Dir
- Perl: Find Replace String Pairs in Directory
- the main show. Writing a find/replace script in WolframLang
the main things you need to do for writing a find replace script.
- walk a dir, recursively
- open file, get content of the file
- do find and replace of a given big string
- how to write to a file
PowerShell. find replace all html files in a dir, recursive:
Get-ChildItem "c:/Users/xah/" -Recurse -Include *html | ForEach-Object { (Get-Content $_) -replace "elephant", "tiger" | Out-File $_.fullname }
shorter version using alias:
dir "c:/Users/xah/" -Recurse -Include *html | % { (gc $_) -replace "elephant", "tiger" | Out-File $_.fullname }
WolframLang. find replace all html files in a dir, recursive:
WriteString[#, StringReplace[ReadString@#, "elephant"->"tiger"]]& /@ FileNames["*html","c:/Users/xah/"]