How do I replace foo. with foo_ with sed simply running
sed 's/foo./foo_/g' file.php
doesn't work. Thanks!
You need to escape the special characters with a backslash \ in front of the special character. For your case, escape every special character with backslash \ .
Find and replace text within a file using sed command Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input.txt. The s is the substitute command of sed for find and replace.
\b marks a word boundary, either beginning or end. Now consider \b' . This matches a word boundary followed by a ' . Since ' is not a word character, this means that the end of word must precede the ' to match. To use \b to match at beginnings of words, reverse the order: '\b .
Escape the .
:
sed 's/foo\./foo_/g' file.php
Example:
~$ cat test.txt foo.bar ~$ sed 's/foo\./foo_/g' test.txt foo_bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With