Xah Talk Show 2021-10-15 grep/sed find/replace in WolframLang elisp golang python perl PowerShell

Xah Talk Show 2021-10-15 grep/sed find/replace in WolframLang elisp golang python perl PowerShell

the main things you need to do for writing a find replace script.

  1. walk a dir, recursively
  2. open file, get content of the file
  3. do find and replace of a given big string
  4. 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/"]

xah_talk_show_2021-10-15.txt