sed command line tool

sed is not new for me. But it’s such a versatile tool. And I always have trouble finding the precice syntax I need. So here is a collection of examples. It probably will grow in the years.

Replace the home dir with ~.

COMPACT=$(echo ${HOME} | sed "s#${HOME}#~#g")

Replace %SALT% with the variable $SALT in the file wp-config.php

sudo sed -i -E "s/%SALT%/$SALT/g"  "wp-config.php"

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.