sed + remove “#” and empty lines with one sed command

后端 未结 7 2063
旧巷少年郎
旧巷少年郎 2020-12-08 02:57

how to remove comment lines (as # bal bla ) and empty lines (lines without charecters) from file with one sed command?

THX lidia

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 03:27

    On (one of) my linux boxes, sed understands extended regular expressions with the -r option, so:

    sed -r '/(^\s*#)|(^\s*$)/d' squid.conf.installed

    is very useful for showing all non-blank, non comment lines. The regex matches either start of line followed by zero or more spaces or tabs followed by either a hash or end of line, and deletes those matching lines from the input.

提交回复
热议问题