What does the
# character mean in this line:
/bin/sed -e 's#abc#zzz#g'
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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
You could use
sed 's/https:\/\/askubuntu.com\/questions/https:\/\/askubuntu.com\/posts/' file
But better to use
sed 's|https://askubuntu.com/questions|https://askubuntu.com/posts|' file
It's a separator, just like
"/", it's same as
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'