How to replace braces symbol in Linux ?
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.
Option | Description |
---|---|
-c, -C, –complement | This option is used to add a complement to SET1. |
-d, –delete | used to delete specific characters in SET1. |
-s, –squeeze-repeats | replace each sequence of a repeated character. |
-t, –truncate-set1 | truncate set1 to the length of set2. |
–help | display 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:
Please Login to comment...