Using sed to replace special characters

sed

This works to replace tom with sam in a file:

sed 's/tom/sam/g' file_1 > file_2

But this does not:

sed 's/*****/sam/g' file_1 > file_2

To replace the special characters ***** with the word sam. I have tried with a slash \* but errors.

Best Answer

You need to escape the special characters with a backslash \ in front of the special character, e.g.:

sed 's/\*/t/g' test.txt > test2.txt

Related Question