Both Notepad++ in Windows and Vim in unix-type machines are perfectly capable of using regular expressions which is a super handy tool in an admin's hands.
Example text:
#HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_ecdsa_key #HostKey /etc/ssh/ssh_host_ed25519_key # Ciphers and keying #RekeyLimit default none # Logging #SyslogFacility AUTH #LogLevel INFO # Authentication: #LoginGraceTime 2m PermitRootLogin prohibit-password #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # HostbasedAuthentication
Notepad++
To remove commented lines from files we can use the following expression in Notepad++:
^(\h*#.*)
It creates a capturing group that includes all possible horizontal white spaces at the beginning of each line. This part is discretional, if all commented lines start with the hash character we can omit it. The next part is the actual hash character (#) - this is what marks a comment - , then all the following contents are included in the regular expression.
Next, we tell the program to replace it with nothing
To see how to remove empty lines with Notepad++, click here.
Vim
Use the following command in command mode:
:%s:^\s*#.*::
For a guide on how to remove empty lines in Vim, check out the guide here.
Comments