0
0
Bash Scriptingscripting~5 mins

tr for character transformation in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the tr command do in bash scripting?
The tr command translates or deletes characters from input. It is used to transform characters, like changing lowercase letters to uppercase.
Click to reveal answer
beginner
How do you use tr to convert all lowercase letters to uppercase?
Use tr 'a-z' 'A-Z'. It replaces every lowercase letter with its uppercase equivalent.
Click to reveal answer
intermediate
What happens if the input contains characters not in the first set of tr?
Characters not in the first set are passed through unchanged. tr only transforms characters it matches in the first set.
Click to reveal answer
intermediate
How can you delete characters using tr?
Use the -d option with the characters to delete. For example, tr -d 'aeiou' deletes all vowels from the input.
Click to reveal answer
beginner
Explain the difference between tr 'a-z' 'A-Z' and tr 'A-Z' 'a-z'.
tr 'a-z' 'A-Z' converts lowercase letters to uppercase. tr 'A-Z' 'a-z' converts uppercase letters to lowercase.
Click to reveal answer
Which tr command converts all lowercase letters to uppercase?
Atr 'a-z' 'A-Z'
Btr 'A-Z' 'a-z'
Ctr -d 'a-z'
Dtr '0-9' 'a-z'
What does tr -d 'aeiou' do?
AConverts vowels to uppercase
BReplaces vowels with numbers
CDeletes all vowels from input
DDuplicates vowels in input
If input contains digits and you run tr 'a-z' 'A-Z', what happens to digits?
ADigits remain unchanged
BDigits are deleted
CDigits are converted to uppercase letters
DDigits are replaced with spaces
Which command deletes all spaces from input?
Atr -s ' '
Btr ' ' '-'
Ctr 'a-z' 'A-Z'
Dtr -d ' '
What is the output of echo 'Hello123' | tr 'A-Z' 'a-z'?
AHELLO123
Bhello123
CHello123
DhELLO123
Describe how to use tr to change all lowercase letters in a text to uppercase.
Think about replacing one set of characters with another.
You got /4 concepts.
    Explain how to remove specific characters from input using tr.
    Deleting means removing characters completely.
    You got /4 concepts.