Linux | How to grep only uncommented contents from any configuration file

Author - Navneet Kashyap

Problem : How to grep only uncommented contents from any configuration file which is big in size, has many comments and blank lines

Solution: This can be achieved by following single command :

# grep -v '^$' /etc/httpd/conf/httpd.conf | grep -v '^ *#' | less

Explanation of command :

^$ : Matches and removes all blank lines
^ *# : Matches and removes all comments that starts with a “#” even with more spaces.
-v : To invert the selection
| less : To pipe the result in scroll format.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need any software development assistance please contact us at dev@webners.com

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *