sed commands
15 commands, each with a one-line explanation. Click a command to copy it, or its title for details.
Commands 15 shown
-
sed 's/foo/bar/' file.txtReplace the first occurrence of 'foo' with 'bar' per line
-
sed 's/foo/bar/g' file.txtReplace every occurrence per line with the /g flag
-
sed -i 's/old/new/g' config.cfgModify file in-place (no backup); on macOS add empty string: -i ''
-
sed -i.bak 's/old/new/g' file.txtEdit in-place and save original as file.txt.bak
-
sed '/^#/d' config.txtDelete all comment lines starting with #
-
sed '/^[[:space:]]*$/d' file.txtRemove all empty or whitespace-only lines
-
sed -n '10,20p' file.txtPrint lines 10 through 20 only (suppress default output with -n)
-
sed -n '/ERROR/p' app.logPrint only lines that match ERROR
-
sed '/^server_name/i # Added by deploy script' nginx.confInsert a comment line before every server_name directive
-
sed '/^\[defaults\]/a ansible_python_interpreter=/usr/bin/python3' ansible.cfgAppend a setting line after the [defaults] header
-
sed 's/error/ERROR/gI' file.txtGNU sed /I flag for case-insensitive match
-
sed -e 's/foo/bar/g' -e 's/baz/qux/g' file.txtApply multiple substitutions in one command
-
sed 's/^[[:space:]]*//;s/[[:space:]]*$//' file.txtTrim leading and trailing whitespace from each line
-
sed '5,15s/DEBUG/INFO/g' app.logApply substitution only to lines 5 through 15
-
sed -n 's/^DB_HOST=//p' .envPrint the value of DB_HOST from a .env file
no commands match — try a different search