What do the dots in this tr command do: tr …A-Z A-ZA-Z <<< “JVPQBOV” (with 13 dots)

tr

I want to use tr to do some rot13 transformation. I can beautifully understand this command:

tr A-Za-z N-ZA-Mn-za-m <<< "URYC ZR CYRNFR"

which output is HELP ME PLEASE, but I can't figure out how this other command can produce the same rot13 transformation:

tr .............A-Z A-ZA-Z <<< "URYC ZR CYRNFR"

So I have two questions:

  1. What's the magic behind the second tr command?
  2. How to make the second command work for both lower and upper case, just like the first command?

Best Answer

It works as follows:

SET1-> .............ABCDEFGHIJKLMNOPQRSTUVWXYZ
SET2-> ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM

So tr will translate SET1 to SET2.

This is equivalent to first one because it is also shifting by 13 units as there 13 dots.

To include the lower case letters, you'll have to arrange them in SET1 with a similar offset, i.e.:

.............ABCDEFGHIJKLMNOPQRSTUVWXYZ..........................abcdefghijklmnopqrstuvwxyz

ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklm

That's 26 dots between Z and a, spanning half the upper-case and half the lower-case alphabet. So the tr command itself will be:

tr .............A-Z..........................a-z A-ZA-Za-za-z