Print lines matching pattern sed
Print only lines that match ERROR
sed -n '/ERROR/p' app.log
more sed
all 15 commands →
Insert line before match
sed '/^server_name/i # Added by deploy script' nginx.conf
Append line after match
sed '/^\[defaults\]/a ansible_python_interpreter=/usr/bin/python3' ansible.cfg
Case-insensitive substitution
sed 's/error/ERROR/gI' file.txt
Multiple expressions
sed -e 's/foo/bar/g' -e 's/baz/qux/g' file.txt
Strip leading/trailing whitespace
sed 's/^[[:space:]]*//;s/[[:space:]]*$//' file.txt