sed Replace String in File
Use sed to replace text in one file or many files, with examples for Linux and macOS.
Replace First Match Per Line
sed 's/old/new/' app.confReplace All Matches Per Line
sed 's/old/new/g' app.confEdit File In Place
# GNU sed
sed -i 's/old/new/g' app.conf
# macOS/BSD sed
sed -i '' 's/old/new/g' app.confCommon Mistake
macOS sed requires an argument after -i. Use -i '' for no backup, or -i .bak to create a backup file.
Related
Knowledge is power.