Quickly Remove Comments from Configuration Files

Configuration files can be long and complex and it is hard to see which values have been set. There are numerous ways to do this however, grep with -v (–invert-match) is a quick way to achieve this. The following example removes all the comments from an elasticsearch configuration file:

[email protected]:~$ sudo grep -v '#' /etc/elasticsearch/elasticsearch.yml

Which returns:

cluster.name: es
node.name: es01
discovery.zen.ping.unicast.hosts: ["", ""]
discovery.zen.minimum_master_nodes: 2

Five lines where it is easy to see what has been configured. Rather than:

[email protected]:~$ sudo wc -l /etc/elasticsearch/elasticsearch.yml
94 /etc/elasticsearch/elasticsearch.yml

So we have removed 89 lines of comments and can review the configuration in five. Time saved!

Written on October 14, 2016