Edit a file in place
Change the file in place without a backup; on macOS use -i ''
sed -i 's/old/new/g' config.cfg
- tool
- sed15 commands
More sed commands
-
sed -i.bak 's/old/new/g' file.txtEdit in place and keep the original as file.txt.bak
-
sed '/^#/d' config.txtDelete all comment lines that start with #
-
sed '/^[[:space:]]*$/d' file.txtRemove empty lines and lines with only spaces
-
sed -n '10,20p' file.txtPrint only lines 10-20; -n turns off the default output
-
sed -n '/ERROR/p' app.logPrint only lines that contain ERROR