{"id":13292,"date":"2019-04-01T11:32:56","date_gmt":"2019-04-01T11:32:56","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13292"},"modified":"2019-04-01T11:32:56","modified_gmt":"2019-04-01T11:32:56","slug":"how-to-view-configuration-files-without-comments-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-view-configuration-files-without-comments-in-linux\/","title":{"rendered":"How to View Configuration Files Without Comments in Linux"},"content":{"rendered":"<p>Are you looking through an extremely lengthy configuration file, one with hundreds of lines of comments, but only want to filter the important settings from it. In this article, we will show you different ways to view a configuration file without comments in Linux.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/cat-command-output-with-syntax-highlighting-or-color\/\" target=\"_blank\" rel=\"noopener\">ccat \u2013 Show \u2018cat Command\u2019 Output with Syntax Highlighting or Colorizing<\/a><\/p>\n<p>You can use the\u00a0<a href=\"https:\/\/www.tecmint.com\/12-practical-examples-of-linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep command<\/a>\u00a0to for this purpose. The following command will enable you view the current configurations for\u00a0<strong>PHP 7.1<\/strong>\u00a0without any comments, it will remove lines starting with the\u00a0<code>;<\/code>\u00a0character which is used for commenting.<\/p>\n<p>Note that since\u00a0<code>;<\/code>\u00a0is a special shell character, you need to use the\u00a0<code>\\<\/code>\u00a0escape character to change its meaning in the command.<\/p>\n<pre>$ grep ^[^\\;] \/etc\/php\/7.1\/cli\/php.ini\r\n<\/pre>\n<div id=\"attachment_28266\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/View-Files-without-Comments.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28266\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/View-Files-without-Comments.png\" alt=\"View Files Without Comments \" width=\"692\" height=\"344\" aria-describedby=\"caption-attachment-28266\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28266\" class=\"wp-caption-text\">View Files Without Comments<\/p>\n<\/div>\n<p>In most configuration files, the\u00a0<code>#<\/code>\u00a0character is used for commenting out a line, so you can use the following command.<\/p>\n<pre>$ grep ^[^#] \/etc\/postfix\/main.cf\r\n<\/pre>\n<p>What if you have lines starting with some\u00a0<strong>spaces<\/strong>\u00a0or\u00a0<strong>tabs<\/strong>\u00a0other then\u00a0<code>#<\/code>\u00a0or\u00a0<code>;<\/code>\u00a0character?. You can use the following command which should also remove empty spaces or lines in the output.<\/p>\n<pre>$ egrep -v \"^$|^[[:space:]]*;\" \/etc\/php\/7.1\/cli\/php.ini \r\nOR\r\n$ egrep -v \"^$|^[[:space:]]*#\" \/etc\/postfix\/main.cf\r\n<\/pre>\n<div id=\"attachment_28268\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/View-Files-Without-Spaces.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28268\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/View-Files-Without-Spaces.png\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/View-Files-Without-Spaces.png 782w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/12\/View-Files-Without-Spaces-768x301.png 768w\" alt=\"View Files Without Spaces\" width=\"782\" height=\"306\" aria-describedby=\"caption-attachment-28268\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28268\" class=\"wp-caption-text\">View Files Without Spaces<\/p>\n<\/div>\n<p>From the above example, the\u00a0<code>-v<\/code>\u00a0switch means show non-matching lines; instead of showing matched lines (it actually inverts the meaning of matching) and in the pattern\u00a0<strong>\u201c^$|^[[:space:]]*#\u201d<\/strong>:<\/p>\n<ul>\n<li><code>^$<\/code>\u00a0\u2013 enables for deleting empty spaces.<\/li>\n<li><code>^[[:space:]]*#<\/code>\u00a0or\u00a0<code>^[[:space:]]*;<\/code>\u00a0\u2013 enables matching of lines that starting with\u00a0<code>#<\/code>\u00a0or\u00a0<code>;<\/code>\u00a0or \u201csome spaces\/tabs.<\/li>\n<li><code>|<\/code>\u00a0\u2013 the infix operator joins the two regular expressions.<\/li>\n<\/ul>\n<p>Also learn more about\u00a0<strong>grep command<\/strong>\u00a0and its variations in these articles:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/difference-between-grep-egrep-and-fgrep-in-linux\/\" target=\"_blank\" rel=\"noopener\">What\u2019s Difference Between Grep, Egrep and Fgrep in Linux?<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/linux-grep-commands-character-classes-bracket-expressions\/\" target=\"_blank\" rel=\"noopener\">11 Advanced Linux \u2018Grep\u2019 Commands on Character Classes and Bracket Expressions<\/a><\/li>\n<\/ol>\n<p>That\u2019s all for now! We would love to hear from you, share with us any alternative methods for viewing configuration files without comments, via the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/view-files-without-comments-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you looking through an extremely lengthy configuration file, one with hundreds of lines of comments, but only want to filter the important settings from it. In this article, we will show you different ways to view a configuration file without comments in Linux. Read Also:\u00a0ccat \u2013 Show \u2018cat Command\u2019 Output with Syntax Highlighting or &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-view-configuration-files-without-comments-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to View Configuration Files Without Comments in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13292","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13292"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13292\/revisions"}],"predecessor-version":[{"id":13293,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13292\/revisions\/13293"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}