Horje
How to View Configuration Files Without Comments in Linux?

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

How to View Configuration Files Without Comments in Linux

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

How to View Configuration Files Without Comments in Linux

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.
  • ^[[:space:]]
  • *# or ^[[:space:]]
  • *; — allows you to align lines that begin with # or ; or “any spaces/tabs.”



Reffered: https://www.geeksforgeeks.org


How To

Related
Recon-ng Information gathering tool in Kali Linux Recon-ng Information gathering tool in Kali Linux
Backup & Restore Files using Windows File History Backup & Restore Files using Windows File History
How to Put a Shutdown Timer on your Windows Desktop? How to Put a Shutdown Timer on your Windows Desktop?
Change the Default DNS Server of Your Router and Windows Computer Change the Default DNS Server of Your Router and Windows Computer
How to Search Files using CMD? How to Search Files using CMD?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
15