Useful sed

This is going to be a really small post. Sometimes there are a lot of comments on files. How do we clean it up a little? Using sed. Lets show an example.

[14:21:55] xavi@NewYork:/tmp $ sed -e '/^#/d' /etc/ssh/sshd_config | sed -e '/^$/d'
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
[14:22:06] xavi@NewYork:/tmp $

First sed removes lines starting with a #. Our input file is the sshd config file, but it can be any other. The output is then piped to remove the empty lines leaving us with a clean configuration file.

Comments are always welcome. Yes, I know there are some security flaws in the config file, but that is not what we are dealing with in this howto. 🙂
References:

  1. http://www.grymoire.com/Unix/Sed.html
  2. http://en.wikipedia.org/wiki/Sed

Leave a Reply