Small sed cheatsheet

Sed is a brilliant function to delete or replace strings. I often used sed for replacing (a group of) words or deleting lines.

How to remove a line containing a string in sed:

sed -i '/string/d' /home/admin/filename.txt

How to replace a string in sed:

sed -i 's/#Port 22/Port 12340/g' /etc/ssh/sshd_config

How to remove white lines from ie a .ini file with sed:

sed -i '/^\s*$/d' /usr/local/directadmin/conf/directadmin.conf

Published by

Maarten Keizer

Hosting guru. WordPress addict. n00b programmer.

Leave a Reply

Your email address will not be published. Required fields are marked *