HackerRank - 'Tr' Command #1
April - 25/2025Problem:
In this challenge, we practice using the tr command because it is a useful translation tool in Linux. In a given fragment of text, replace all parentheses () with box brackets [].
# Input
- int i=(int)5.8
- (23 + 5)*2
# Output
- int i=[int]5.8
- [23 + 5]*2
# Solution
tr "(" "[" | tr ")" "]"
# Solution_01
tr '()' '[]'
# Solution_02
while read line
do
echo $line | tr "()" "[]";
done
echo $line | tr "()" "[]";