title: remove comments without affecting values in the config file
body: <p>I have a config file and I need to remove the comments starting with # to the end of the line.
  But it should not affect the values that are in double/single quotes.</p>
  
  <p>My input file:</p>
  
  <pre><code># comment1
  # comment2
  #hbase_table_name=mytable # hbase table.
  hbase_table_name=newtable # hbase table.
  hbase_txn_family=txn
  app_name= "cust#100"  # Name of the application
  app_user= 'all#50,all2#100'  # users
  hbase.zookeeper.quorum=localhost
  zookeeper.znode.parent=/hbase-secure
  hbase.zookeeper.property.clientPort=2181
  </code></pre>
  
  <p>The perl command that I'm trying</p>
  
  <pre><code>perl -0777 -pe ' s/^\s*$//gms ; s/#.*?$//gm; s/^\s*$//gms;s/^$//gm' config.txt
  </code></pre>
  
  <p>The output I'm getting is </p>
  
  <pre><code>hbase_table_name=newtable
  hbase_txn_family=txn
  app_name= "cust
  app_user= 'all
  hbase.zookeeper.quorum=localhost
  zookeeper.znode.parent=/hbase-secure
  hbase.zookeeper.property.clientPort=2181
  </code></pre>
  
  <p>But the required output is </p>
  
  <pre><code>hbase_table_name=newtable
  hbase_txn_family=txn
  app_name= "cust#100"
  app_user= 'all#50,all2#100'
  hbase.zookeeper.quorum=localhost
  zookeeper.znode.parent=/hbase-secure
  hbase.zookeeper.property.clientPort=2181
  </code></pre>
  
  <p>I'm looking for a bash solution using any tools - awk or perl that can solve this.</p>
  
  <p>A rare scenario may be with config entry like</p>
  
  <pre><code>app_user= 'all#50,all2#100'  # users - "all" of them
  </code></pre>
  
  <p>and the result should be <code>app_user= 'all#50,all2#100'</code></p>