How do you replace text across many files safely?
IntermediateConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
grep -rlZ --include='*.yaml' 'registry.old.io' k8s/ |
xargs -0 sed -i 's|registry\.old\.io|registry.new.io|g'
git diff --stat # review before committing
grep -l lists only files that need changes, so unrelated files keep their mtime. -Z/-0 handle odd filenames. Escape . in the pattern (it means "any character" in regex). Run it in a Git working tree so you can review and revert.
More on Text processing: grep, sed, awk, cut, sort, uniq
What are the most useful `grep` flags?BeginnerWhat is the difference between basic, extended and Perl regular expressions in grep?IntermediateWhat are the core `sed` commands you use in automation?BeginnerWhy does `sed -i` behave differently on macOS and Linux?IntermediateHow do you use variables inside a `sed` expression safely?AdvancedWhat is the structure of an `awk` program?Beginner