How to replace braces symbols in Unix / Linux

  • Updated
  • Posted in Programming
  • 1 min read


Q) My log file comprises the braces symbols ‘(‘ and ‘)’. I would love to replace the braces with empty string. Sample information in the log file is proven beneath:

> cat logfile
Error - (unix script failed)

The output shouldn’t comprise the braces and the information ought to look as

Error - unix script failed

How am i able to obtain this utilizing unix or linux instructions?

Solution:

1. Replacing utilizing tr command

We can use the tr command to delete characters in a file. The deleting of strings utilizing tr command is proven beneath:

tr -d '()' < logfile

2. Replacing utilizing sed command Sed command is popularly used for changing the textual content in a file with one other textual content. The sed command is

sed 's/[()]//g' logfile

Another means of changing is utilizing sed with pipes in unix:

sed 's/(//' logfile| sed 's/)//'

Leave a Reply