BASH from beginner to advanced: Solutions to Hackerrank Challenges - Episode 17: Tr Command

Опубликовано: 12 Июль 2026
на канале: Adam Djellouli
139
3

Welcome to this comprehensive series of videos where we will be giving solutions and explanations for various BASH challenges from Hackerrank. In this video, we will be addressing 3 tasks, including "'Tr' Command #1" (https://www.hackerrank.com/challenges..., "'Tr' Command #2" (https://www.hackerrank.com/challenges..., "'Tr' Command #3" (https://www.hackerrank.com/challenges....

Our goal in this series is to document my thought process and solutions, and to focus on concepts and ideas rather than details. I will also be highlighting the differences between BASH and popular programming languages like Python and JavaScript.

BASH is a powerful command-line interface for interacting with an operating system. It's a shell, and the most popular one. It can be used directly in the terminal or in scripts, which are text files containing a series of instructions. BASH is particularly useful for tasks such as text processing, file operations, connecting multiple programs, and system maintenance. It is also portable, working by default on many platforms.

The tr command is a Unix/Linux utility that is used to translate, replace, or delete characters from standard input and write the result to standard output. The tr command can be used to perform a variety of tasks, such as:

Translating characters: tr can be used to translate one set of characters to another. For example, to convert all uppercase letters to lowercase letters, you can use the command:

$ echo "HELLO WORLD" | tr '[:upper:]' '[:lower:]'
hello world

Here, the tr command translates all uppercase characters to lowercase characters using the [:upper:] and [:lower:] character classes.

Deleting characters: tr can also be used to delete specific characters from the input. For example, to remove all the vowels from a string, you can use the command:

$ echo "hello world" | tr -d 'aeiou'
hll wrld

Here, the -d option specifies that the specified characters should be deleted from the input.

Squeezing characters: tr can also be used to squeeze multiple consecutive occurrences of a character into a single character. For example, to remove duplicate spaces from a string, you can use the command:

$ echo "hello world" | tr -s ' '
hello world

Here, the -s option squeezes multiple spaces into a single space.

If you want to see all the solutions for these challenges, you can find them on my Github repository: https://github.com/djeada/Bash-Hacker...

Also, you can find me on my website: https://adamdjellouli.com/ where I write about different programming topics, and you can see my other projects.

Don't forget to like and subscribe for more BASH tutorials and solutions to Hackerrank challenges.