FMeinicke's Wiki

Home

❯

Linux

❯

Commands

❯

sed

❯

Comment and uncomment lines

Comment and uncomment lines

May 26, 20251 min read

  • sed

sed

Source

  • https://stackoverflow.com/a/27355109/12780516
  • to comment a line (and preserve indentation)

    sed -Ei '/<pattern>/s/^(\s*)/\1# /g'
  • to uncomment a line (and preserve indentation)

    sed -Ei '/<pattern>/s/^(\s*)#\s?/\1/g'

Graph View

Created with Quartz v4.5.0 © 2025

  • GitHub