Filter

Delete comment lines

Delete lines that start with comment markers such as #.

What this template solves

Use this template when you need to remove commented rows from config, shell snippets, or generated files without touching active lines.

Open the workspace with this template preloaded, then refine it for your own file and text pattern.

Sample input

# generated file
DB_HOST=localhost
# keep secret out

Prompt to start from

Delete lines that start with # in the file

Expected command

sed '/^#/d'

Tags

filtercommentscleanupconfig

Best for

  • Remove comment rows from env, ini, or shell snippets.
  • Clean generated files before passing them to another tool.
  • Strip explanatory comment lines from exported config examples.

How to use this template

  1. 1Check which comment marker the file uses at the start of each comment line.
  2. 2Copy the sed command that deletes matching comment rows.
  3. 3Preview on a short sample first, then run the in-place file-edit command if the output looks correct.

Template FAQ

How do I delete comment lines that start with # using sed?

A common pattern is `sed '/^#/d'`, which deletes lines beginning with a comment marker. This is useful for cleaning config examples, shell snippets, or generated files before passing them downstream.

Will delete-comment-lines remove active config rows too?

No, as long as the pattern is scoped to the comment marker at the start of the line. It only targets lines that look like comments and leaves active rows intact.

Related templates

Explore nearby sed workflows that target similar replace, cleanup, filtering, or rewrite tasks.

Delete comment lines Sed Template | AskSed