Edit in place with a backup
Edit in place and keep the original as file.txt.bak
sed -i.bak 's/old/new/g' file.txt
- tool
- sed15 commands
More sed commands
-
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
-
sed '/^server_name/i # Added by deploy script' nginx.confInsert a comment line before each server_name directive