Replace text in a file with sed and keep a backup
sed find and replace in file | search and replace command line linux | change config value with sed | sed | replace | configurationCaution: This command changes the system. Understand what it does before you run it.
sed -i.bak 's|memory_limit = 128M|memory_limit = 256M|g' php.iniReplaces every occurrence of ALT with NEU in the file itself, while the original stays next to it as php.ini.bak. The | serves as delimiter so that paths with slashes work without escaping. Run it without -i.bak first to safely check the result on the console.
Note: The search text is a regular expression, characters such as ., *, [ or $ have special meaning and must be escaped with a backslash. If the text itself contains a |, choose a different delimiter such as #.
Also searched as
- sed find and replace in file
- search and replace command line linux
- change config value with sed