We came across an extremely long configuration file with hundreds of thousands of comments, and all we wanted to do was filter out the important content or settings. As a result, we’ll look at various methods for viewing configuration files in Linux without comments.
The grep command can be used to do this. The following command will delete lines beginning with the ” ; ” character, which is used for commenting, allowing you to see the latest PHP 7.4 configurations without any comments.
Since ” ; ” is a special shell character, you must use the escape character in the command to alter its context.
$ grep ^[^\;] /etc/php/7.4/cli/php.ini
The # character is used for commenting out of a line, so this command is used in the configuration file.
$ grep ^[^#] /etc/postfix/main.cf
If your lines begin with space or a tab rather than the # or ; the character you use the following command to delete any blank lines or spaces from the output.
$ egrep -v "^$|^[[:space:]]*;" /etc/php/7.4/cli/php.ini OR $ egrep -v "^$|^[[:space:]]*#" /etc/postfix/main.cf
In the pattern “$|[[:space:]]*#,” the -v switch means display non-matching lines instead of matched lines (it literally inverts the sense of matching), and in the pattern “$|[[:space:]]*#,” the -v switch means show non-matching lines instead of matched lines (it actually inverts the meaning of matching).
- $ — Allows you to delete empty spaces.
- | — joins the two regular expressions with the infix operator.
- *# or ^[[:space:]]
- *; — allows you to align lines that begin with # or ; or “any spaces/tabs.”