Basic Linux command (tr)
Cheulong Sear

Cheulong Sear @cheulong

About: Hi, I’m Cheulong Sear. Love learning new staff. I will show my journey in the IT field and what I'm building during my free time.

Location:
Bangkok, Thailand
Joined:
Jun 30, 2024

Basic Linux command (tr)

Publish Date: Jul 29
1 0

tr is used to translate, squeeze, and/or delete characters from standard input, writing to standard output.

tr command is usually used alone side with other command.

echo "Hello World" | tr [a-z] [A-Z]
# or echo "Hello World" | tr [:lower:] [:upper:]
----
# output:
HELLO WORLD
Enter fullscreen mode Exit fullscreen mode
echo "Hello World!" | tr "!" "."
----
# output:
Hello World.
Enter fullscreen mode Exit fullscreen mode

You can also delete character with tr command

echo "Hello World" | tr -d [a-z]

----
# output:
H W
Enter fullscreen mode Exit fullscreen mode

Another feature is squeeze, we can remove the duplicate character

echo "localhostt" | tr -s "t"

----
# output:
localhost
Enter fullscreen mode Exit fullscreen mode

Other arguement

[:alnum:] all letters and digits
[:alpha:] all letters
[:blank:] all horizontal whitespace
[:digit:] all digits
[:graph:] all printable characters, not including space
[:lower:] all lower case letters
[:print:] all printable characters, including space
[:punct:] all punctuation characters
[:space:] all horizontal or vertical whitespace
[:upper:] all upper case letters

Leave a comment if you have any questions.

===========
Please keep in touch
Portfolio
Linkedin
Github
Youtube

Comments 0 total

    Add comment