Search code examples
regexsedpcre

replacing special characters using SED


I am having following fields and using SED i need to remove special characters to remove [ ] with space

Retrieve [File
Monitor [FW] end
Monitor [FW] start
Monitor [DR] end
Monitor DR] start
Open File
Set Password
Logon
Logoff
Monitor Backup] end
Monitor Backup] start
Auto Clear] History end
Auto Clear] History start
Old [Backup Deletion End

I have used following SED command

 "s/(\[\w+\])|(\w+\[)|(\w+\])/ /g"

But it is skipping the one with no special characters


Solution

  • You may use

    sed 's/[][]/ /g' file > newfile
    

    The [][] pattern matches a [ or ] and g makes sed replace all occurrences on a line.

    See an online sed demo.