What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

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

As @Prvt_Yadv says in their answer, it works because there are 13 dots.

The sets are

First set:  .............ABCDEFGHIJKLMNOPQRSTUVWXYZ
Second set: ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ

The dot isn't a special character, so if you have a dot in your input, it will be translated too. In the version of tr that I have, it is the last corresponding character in the second set, in this case an M:

$ echo URYC ZR CYRNFR. | tr .............A-Z A-ZA-Z
HELP ME PLEASEM

(I could imagine that a different version of tr might use the first matching character in set 2, which would give an A.)

To answer your second question, you need another 13 dots in the first set to "use up" the remaining uppercase letters in set 2:

First set:  .............ABCDEFGHIJKLMNOPQRSTUVWXYZ.............
Second set: ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ

then you can repeat the pattern:

First set:  .............ABCDEFGHIJKLMNOPQRSTUVWXYZ..........................abcdefghijklmnopqrstuvwxyz
Second set: ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz

which gives us:

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

And so:

$ echo Uryc zr cyrnfr | tr .............A-Z..........................a-z A-ZA-Za-za-z
Help me please

Personally, I think the first way of doing it in your question is simpler!

The first way also doesn't transform any other characters in the input. For example, compare:

$ echo Uryc zr cyrnfr. | tr .............A-Z..........................a-z A-ZA-Za-za-z  
Help me pleasem

with

$ echo Uryc zr cyrnfr. | tr A-Za-z N-ZA-Mn-za-m
Help me please.

Tags:

Tr