linuxshellunix

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

  • 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