'replace special character [ and ] including . using sed

I would like to replace the [sample]. with space in all my document.Could someone let me know how can I do this.I tried the below command but it doesn't work.thanks.

sed -I 's/[sample]./ /g' filename.txt

due to use of [] and . I am having different output. I really appreciate your help



Solution 1:[1]

You need to escape the special characters with \. Also, there's no -I option, the option to update the file in place is -i.

sed -i 's/\[sample\]\./ /g' filename.txt

Solution 2:[2]

This is really simple my Friend . lets see I have task. Replace all occurrence of string #%$2jh//238720//31223 with $2//23872031223 in /home/bob/data.txt file.

now the solution is there ever you see special character just replace is with \ just like i do as below.

sed -i 's/#%$2jh//238720//31223/$2//23872031223/g' /home/bob/data.txt

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar
Solution 2 Asfandyar Saeed