Quick Tip: Sed delimiter doesn’t have to be /

Not only my use of sed hardly goes beyond search and replace, I didn’t know you don’t have to have slash as the delimiter. It can be anything[grymoire.com] you want!

Examples:

$ sed 's/CentOS/centos/' /etc/redhat-release
centos Linux release 7.0.1406 (Core)

$ sed 's\CentOS\centos\' /etc/redhat-release
centos Linux release 7.0.1406 (Core)

$ sed 's|CentOS|centos|' /etc/redhat-release
centos Linux release 7.0.1406 (Core)

$ sed 's_CentOS_centos_' /etc/redhat-release
centos Linux release 7.0.1406 (Core)

$ sed 's:CentOS:centos:' /etc/redhat-release
centos Linux release 7.0.1406 (Core)

If you search term includes a slash, this

$ echo /etc | sed 's:/etc:/tmp:'
/tmp

is much easier to read than

$ echo /etc | sed 's/\/etc/\/tmp/'
/tmp
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s