Answer the question
In order to leave comments, you need to log in
How does the tr utility work in this case?
There is such an example with HTB:
echo https://www.hackthebox.eu/ | tr 'A-Za-z' 'N-ZA-Mn-za-m'
- here it is interesting that in set1 and set2 - several replacement sets are indicated, but so far I read about tr on the Internet - I did not find a similar example - I tried to play around with the tr utility, for example like this: echo 'example123' | tr 'a-z1-9' '1-9A-Z'
- I wanted to replace all letters with numbers, and the remaining digits at the end of the line (123) - into uppercase letters. Got this output:5O1DGC5RST- tried just to replace letters with numbers:
echo 'example123' | tr 'a-z' '1-9'
- Output:5919995123- that's what remains unclear - how such an indication of sets works - i.e. first, the range az - changes to the range 1-9 from the second set, and then 1-9 to AZ (but judging by the output, this is not so - because otherwise -
5O1DGC5RST-would there be only letters ) or such a replacement: the first character of the string (odd) - changes according to the principle: 'az' - '1-9' , and even characters - according to the principle - '1-9' - 'AZ' , but again, why then in the line
5O1DGC5RST- there are three letters in a row 'DGC' and it does not matter how to count from 0 or 1. Also, about the key
-t
- it is written that if you do not use it (as in my example and do not truncate SET1 - which is the length of SET2) - then:If SET1 is greater than SET2, the last character in the second set replaces all remaining characters of the first set., but in the example
echo 'example123' | tr 'a-z1-9' '1-9A-Z'
- they are equal - because both sets contain two ranges, the total power of which is also equal (ie 'all letters' + 'all digits'='all digits' + 'all letters'). Answer the question
In order to leave comments, you need to log in
tr simply replaces the first with the second in order.
echo 'example123' | tr 'a-z1-9' '1-9A-Z'
in this case, expand both ranges and get abcdefghij... the second will be 123456789ABC...
so a will be replaced by 1, and j by A
and 0 is not specified at all in your range.
Actually two questions:
1. How does it all work?
2. how to replace example123 with digits and 123 with capital letters using the tr utility - in ONE command - without resorting to pipeline ( | ) and stream redirection ( > ) (Is it possible)?
abcdefghijklmnopqrstuvwxyz123456789
123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question