{"id":371,"date":"2010-09-20T14:27:12","date_gmt":"2010-09-20T18:27:12","guid":{"rendered":"http:\/\/www.xavignu.com\/?p=371"},"modified":"2010-09-20T14:34:45","modified_gmt":"2010-09-20T18:34:45","slug":"useful-sed","status":"publish","type":"post","link":"https:\/\/www.xavignu.com\/?p=371","title":{"rendered":"Useful sed"},"content":{"rendered":"<p>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 <a href=\"http:\/\/www.gnu.org\/software\/sed\/\" target=\"_blank\">sed<\/a>. Lets show an example.<\/p>\n<pre>\r\n[14:21:55] xavi@NewYork:\/tmp $ sed -e '\/^#\/d' \/etc\/ssh\/sshd_config | sed -e '\/^$\/d'\r\nPort 22\r\nProtocol 2\r\nHostKey \/etc\/ssh\/ssh_host_rsa_key\r\nHostKey \/etc\/ssh\/ssh_host_dsa_key\r\nUsePrivilegeSeparation yes\r\nKeyRegenerationInterval 3600\r\nServerKeyBits 768\r\nSyslogFacility AUTH\r\nLogLevel INFO\r\nLoginGraceTime 120\r\nPermitRootLogin yes\r\nStrictModes yes\r\nRSAAuthentication yes\r\nPubkeyAuthentication yes\r\nIgnoreRhosts yes\r\nRhostsRSAAuthentication no\r\nHostbasedAuthentication no\r\nPermitEmptyPasswords no\r\nChallengeResponseAuthentication no\r\nX11Forwarding yes\r\nX11DisplayOffset 10\r\nPrintMotd no\r\nPrintLastLog yes\r\nTCPKeepAlive yes\r\nAcceptEnv LANG LC_*\r\nSubsystem sftp \/usr\/lib\/openssh\/sftp-server\r\nUsePAM yes\r\n[14:22:06] xavi@NewYork:\/tmp $\r\n<\/pre>\n<p>First sed removes lines starting with a #. Our input file is the <a href=\"http:\/\/www.openssh.com\/\" target=\"_blank\">sshd<\/a> 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.<\/p>\n<p>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. \ud83d\ude42<br \/>\nReferences:<\/p>\n<ol>\n<li><a href=\"http:\/\/www.grymoire.com\/Unix\/Sed.html\" target=\"_blank\">http:\/\/www.grymoire.com\/Unix\/Sed.html<\/a><\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Sed\" target=\"_blank\">http:\/\/en.wikipedia.org\/wiki\/Sed<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8216;\/^#\/d&#8217; \/etc\/ssh\/sshd_config | sed -e &#8216;\/^$\/d&#8217; Port 22 Protocol 2 HostKey \/etc\/ssh\/ssh_host_rsa_key HostKey \/etc\/ssh\/ssh_host_dsa_key UsePrivilegeSeparation yes KeyRegenerationInterval 3600 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3],"tags":[22,6,23,70],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pTQgt-5Z","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/371"}],"collection":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=371"}],"version-history":[{"count":0,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/371\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}