Interestingly, if you want to search for and replace just the dot, you have to put the dot in a character set. Escaping just the dot alone in a sed command for some reason doesn't work. The dot is still expanded to a single character wild card.
$ bash --version # Ubuntu Lucid (10.04)
GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)
$ echo aa.bb.cc | sed s/\./-/g # replaces all characters with dash
'--------'
$ echo aa.bb.cc | sed s/[.]/-/g # replaces the dots with a dash
aa-bb-cc
With the addition of leading characters in the search, the escape works.
$ echo foo. | sed s/foo\./foo_/g # works
foo_
Putting the dot in a character set of course also works.
Interestingly, if you want to search for and replace just the dot, you have to put the dot in a character set. Escaping just the dot alone in a sed command for some reason doesn't work. The dot is still expanded to a single character wild card.
GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)
'--------'
aa-bb-cc
With the addition of leading characters in the search, the escape works.
foo_
Putting the dot in a character set of course also works.
foo_
-- Paul
For myself,
sed 's/foo\./foo_/g'
is working. But you can also try:and
and
Escape the dot with a \
If you find the combination of / and \ confusing you can use another 'separator' character
The 2nd character after the s can be anything and sed will use that character as a separator.
You need to escape the dot - an unescaped dot will match any character after foo.
Escape the
.
:sed 's/foo\./foo_/g' file.php
Example: