0
0
Bash Scriptingscripting~20 mins

tr for character transformation in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
tr Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of tr command with character deletion
What is the output of this command?
echo "hello world" | tr -d 'aeiou'
Bash Scripting
echo "hello world" | tr -d 'aeiou'
Ahll wrld
Bhello world
Ch e l l o w o r l d
DSyntax error
Attempts:
2 left
💡 Hint
The -d option deletes characters specified.
💻 Command Output
intermediate
2:00remaining
Transform lowercase to uppercase using tr
What is the output of this command?
echo "bash scripting" | tr 'a-z' 'A-Z'
Bash Scripting
echo "bash scripting" | tr 'a-z' 'A-Z'
ABASH SCRIPTING
Bbash scripting
CBash Scripting
DSyntax error
Attempts:
2 left
💡 Hint
tr replaces characters from the first set with the second set.
💻 Command Output
advanced
2:00remaining
Output of tr with complement and squeeze
What is the output of this command?
echo "aaabbbccc111222333" | tr -cs 'a-z' $'\n'
Bash Scripting
echo "aaabbbccc111222333" | tr -cs 'a-z' $'\n'
Aaaa bbb ccc
B
aaa
bbb
ccc
Caaabbbccc
DSyntax error
Attempts:
2 left
💡 Hint
The -c option complements the set; -s squeezes repeated characters.
💻 Command Output
advanced
2:00remaining
Effect of tr with overlapping sets
What is the output of this command?
echo "123abc" | tr '1-3a-c' 'x-z1-3'
Bash Scripting
echo "123abc" | tr '1-3a-c' 'x-z1-3'
A123abc
BSyntax error
Cxyz123
Dxxx111
Attempts:
2 left
💡 Hint
Characters in the first set are replaced by corresponding characters in the second set.
💻 Command Output
expert
3:00remaining
Count unique characters after tr transformation
What is the number of unique characters in the output of this command?
echo "Hello World! 123" | tr 'A-Za-z' 'n-za-mN-ZA-M' | tr -d ' ' | tr -d '!' | fold -w1 | sort -u | wc -l
Bash Scripting
echo "Hello World! 123" | tr 'A-Za-z' 'n-za-mN-ZA-M' | tr -d ' ' | tr -d '!' | fold -w1 | sort -u | wc -l
A12
B15
C13
D10
Attempts:
2 left
💡 Hint
The first tr applies ROT13 cipher, then spaces and '!' are removed, unique characters counted.