Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to replace braces symbol in Linux ?

  • Last Updated : 29 Jun, 2021

In this article, we will learn to replace the braces symbol from a text file in the Linux system.

We will use the tr command with the -d or –delete option in the Linux/Unix system to remove the braces symbol.  This tr (translate) command is used to translate or delete characters from a file or standard input in the Linux system using a terminal. It is also used to transform uppercase to lowercase, squeezing repeating characters, and basically finding and replacing. 

Syntax:

 tr [OPTION]... SET1 [SET2]

These are the following options available in the tr command. 

OptionDescription
-c, -C, –complementThis option is used to add a complement to SET1.
-d, –deleteused to delete specific characters in SET1. 
-s, –squeeze-repeatsreplace each sequence of a repeated character. 
-t, –truncate-set1truncate set1 to the length of set2.
–helpdisplay the help and exit.
–version display the version information.

Example: Change upper case to lower case for the content of a text file.



To change upper case to lower case from the predefined sets, we use the tr command as shown below. 

$ cat file | tr '[A-Z]' '[a-z]'

Output:

How to remove brace symbols in the Linux system?

To remove the braces symbol from a predefined set of text, we use the tr command with the -d option as shown below.

$ cat file | tr -d '{}'

Output:

How to replace brace symbols in the Linux system? 

To replace the braces symbol from a predefined set of text with something else, we use the tr command. For example, here  “{}” braces are replaced by ‘[]” braces as shown below.

$ tr '{}' '[]' <file

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :