Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
tr command in Linux can be used to trim special characters from a string in bash script. Let's say we want to remove underscore (_) from the string _hello_:
$ echo "_hello_" | tr -d "_"
hello
As you can see the output is hello.

-d flag causes to delete _ from the whole string.

In case you want to delete multiple special characters, that's easy as pie:
$ echo "_sal-am_" | tr -d "_-"
salam

We have removed - and _ from the string above.

Making lower case to uppercase:
tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
asdasd
ASDASD

OR:
tr [:lower:] [:upper:]
asdasd
ASDASD

Turn {} into ():
$ echo '{hello}' | tr '{}' '()'
(hello)

#linux #tr #translate #trim #bash #sysadmin