Skip to content
Advertisement

Bash match on any lines that have any number of whitespace up to #

I need to clean up a config file before a source it. I need to remove any lines that have

  • Start with #
  • Any number of white space then a #
  • blank lines
  • Remove (and including) # and everything after it if line starts with a string.

Example config:

JavaScript

I have this right now

JavaScript

The problem is line 2, # comment any number of space up to a #. How can I match to remove lines like this?

Advertisement

Answer

You may use this awk:

JavaScript

Or if you want to print only key names then use:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement