-
-
Save facelordgists/4494c4505d4d8d098290917a7f6420c6 to your computer and use it in GitHub Desktop.
how to use sed to search and replace strings inside files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Standalone command | |
sed -i 's/old string/new string/g' /home/dude/text-file.txt | |
## use a custom separator | |
sed -i 's:old/folder/path:new/folder/path:g' /home/dude/text-file.txt | |
## dry run | |
sed 's/old string/new string/g' | less |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Combined with find command to search and replace strings inside multiple files | |
sudo find /var/www/example.com/public_html -type f -exec sed -i 's/old string/new string/g' {} \; | |
sudo find /var/www/example.com/public_html -type f -exec sed -i 's:old/folder/path:new/folder/path:g' {} \; | |
sudo find /etc/td-agent/config.d/ -type f -exec sed -i 's:192.168.0.1:192.168.0.2:g' {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment