Find and replace inside files with sed and xargs
I cleaned up my life on the road polluted links by running
rg -l -0 'find' | xargs -0 -I % sed -i '' 's/find/replace/g' "%"
The breakdown is that
rg -l 'regexPattern'gets a list of files with the pattern in the current directory (my Obsidian vault)rg -l -0outputs a null byte at the end of each file path, whilexargs -0delimits file paths with null bytes. This permits file paths with quotes in them.xargs -I % templateCommandreplaces%insidetemplateCommandwith each file passed via stdinsed -i '' 's/search/replace/g filePathreplaces all instances ofsearchwithreplaceinsidefilePath
Helpful for Programming and Bash