Print matching lines

Print only lines that contain ERROR

sed -n '/ERROR/p' app.log

tool
sed15 commands
tags
sedlinuxdebug

More sed commands

  • sed '/^server_name/i # Added by deploy script' nginx.conf

    Insert a comment line before each server_name directive

  • sed '/^\[defaults\]/a ansible_python_interpreter=/usr/bin/python3' ansible.cfg

    Add a setting line after the [defaults] header

  • sed 's/error/ERROR/gI' file.txt

    The /I flag in GNU sed makes the match case-insensitive

  • sed -e 's/foo/bar/g' -e 's/baz/qux/g' file.txt

    Apply several replacements in one command

  • sed 's/^[[:space:]]*//;s/[[:space:]]*$//' file.txt

    Remove spaces at the start and end of each line

all 15 sed commands