What does the # character mean in: /bin/sed -e 's#abc#zzz#g'?

What does the # character mean in this line:

/bin/sed -e 's#abc#zzz#g'

2 Answers

It's a delimiter or separator. The most commonly used one is / as in

sed 's/old/new/' file

But sed will take the first character after the command (s) as delimiter. You can use any convenient character, for example...

sed 's%old%new%' file

This is very useful if the file contains / (or other conventional delimiting characters). You can choose as separator some character that you know you won't need to put into your sed expression, saving you a lot of annoying escaping.

Let's say you want to replace

with

You could use

sed 's/https:\/\/askubuntu.com\/questions/https:\/\/askubuntu.com\/posts/' file

But better to use

sed 's| file
8

It's a separator, just like "/", it's same as 's/abc/zzz/g'.

it means search for "abc" replace it with "zzz", with global flag, means do it for all "abc"s on the line, not just the first one.

You can also use an alternative separator for a pattern address, but in that case, you need to escape it for it to be correctly interpreted:

sed -r '\#abc#p'

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like