Substitute all matches (global)
Replace every occurrence per line with the /g flag
sed 's/foo/bar/g' file.txt
- tool
- sed15 commands
More sed commands
-
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)