Xah Talk Show 2022-01-11 speed comparison find/replace python, perl, PowerShell, elisp, golang, WolframLang

- https://youtu.be/2dpqktSip1U
- Xah Talk Show 2022-01-11 speed comparison find/replace python, perl, PowerShell, elisp, golang, WolframLang
- first, warm up disk. put files to memory. disk access is the bottleneck.
- Python: Find Replace Text in Dir
- Python: Find Replace Regex in Dir
- Golang: Find String (grep) Script
- Golang: Script to Find Replace Multi-Pairs of Regex in a Directory
- Perl: Find Replace String Pairs in Directory
- Emacs: Xah Find Replace (xah-find.el)
- PowerShell: Convert File Line Ending 🚀
- WolframLang: Script to Find/Replace Strings in a Dir
(xah-find-text "commands" "c:/Users/xah/web/xahlee_info/xx/" "\\.html$" nil t)
python error
2022-01-11 12:46:26.537966 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] Input Dir: c:\Users\xah\web\xahlee_info\xx Find string: commands Replace string: commands * 1 c:/Users/xah/web/xahlee_info/xx/elisp/Active-Keymaps.html Traceback (most recent call last): File "c:\Users\xah\git\xah_find_replace\replace.py3", line 111, in <module> replace_string_in_file(dirPath + os.sep + fName) File "c:\Users\xah\git\xah_find_replace\replace.py3", line 83, in replace_string_in_file output_file.write(file_content) File "C:\Python39\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u21d2' in position 6892: character maps to <undefined> ’’’’’⇒
# xah-find-replace accept a piped file object, it'll do find/relpace a line ending to unix convention # sample use: # dir -Recurse -file -Include "*html" | xah-newline-to-unix # 2021-12-16 function xah-find-replace { Process { $content = [IO.File]::ReadAllText($_) if ($content.contains("`r`n")) { Copy-Item $_ ($_.fullname+(Get-Date -Format "~yyyyMMddHHmm~")) $newContent = ($content -replace "`r`n", "`n") [IO.File]::WriteAllText($_, $newContent) } elseif ($content.contains("`r")) { Copy-Item $_ ($_.fullname+(Get-Date -Format "~yyyyMMddHHmm~")) $newContent = ($content -replace "`r", "`n") [IO.File]::WriteAllText($_, $newContent) } } }