Delete matching lines

Delete all comment lines starting with #

sed '/^#/d' config.txt

tool
sed15 commands
tags
sedlinux

More sed commands

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

    Remove all empty or whitespace-only lines

  • sed -n '10,20p' file.txt

    Print lines 10 through 20 only (suppress default output with -n)

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

    Print only lines that match ERROR

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

    Insert a comment line before every server_name directive

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

    Append a setting line after the [defaults] header

all 15 sed commands