I have a file ma.txt and it contains the output of ls -l; when I run the tr command (tr "nik-pc" "root") I get this output:
nik-pc@nik:~$ cat ma.txt
total 52
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 11 11:33 Desktop
lrwxrwxrwx 1 nik-pc nik-pc 2 Mar 8 22:54 di -> hd
drwxr-xr-x 3 nik-pc nik-pc 4096 Mar 13 13:28 Documents
drwxr-xr-x 7 nik-pc nik-pc 4096 Mar 14 18:21 Downloads
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 11 09:39 dwhelper
-rw-r--r-- 1 nik-pc nik-pc 2134 Mar 13 17:40 hd
-rw-r--r-- 1 nik-pc nik-pc 3 Mar 13 15:34 m
-rw-r--r-- 1 nik-pc nik-pc 0 Mar 17 19:48 ma.txt
drwxr-xr-x 3 nik-pc nik-pc 4096 Mar 13 14:58 Music
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 5 12:30 Pictures
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 5 11:44 Public
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 13 15:58 sd
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 5 11:44 Templates
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 5 11:44 Videos
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 11 11:33 xdm-helper
nik-pc@nik:~$ tr "nik-pc" "root" < ma.txt
tttat 52
drwxr-xr-x 2 too-tt too-tt 4096 Mar 11 11:33 Desottt
trwxrwxrwx 1 too-tt too-tt 2 Mar 8 22:54 do -> hd
drwxr-xr-x 3 too-tt too-tt 4096 Mar 13 13:28 Dttutetts
drwxr-xr-x 7 too-tt too-tt 4096 Mar 14 18:21 Dtwtttads
drwxr-xr-x 2 too-tt too-tt 4096 Mar 11 09:39 dwhetter
-rw-r--r-- 1 too-tt too-tt 2134 Mar 13 17:40 hd
-rw-r--r-- 1 too-tt too-tt 3 Mar 13 15:34 t
-rw-r--r-- 1 too-tt too-tt 0 Mar 17 19:48 ta.txt
drwxr-xr-x 3 too-tt too-tt 4096 Mar 13 14:58 Musot
drwxr-xr-x 2 too-tt too-tt 4096 Mar 5 12:30 Pottures
drwxr-xr-x 2 too-tt too-tt 4096 Mar 5 11:44 Pubtot
drwxr-xr-x 2 too-tt too-tt 4096 Mar 13 15:58 sd
drwxr-xr-x 2 too-tt too-tt 4096 Mar 5 11:44 Tetttates
drwxr-xr-x 2 too-tt too-tt 4096 Mar 5 11:44 Vodets
drwxr-xr-x 2 too-tt too-tt 4096 Mar 11 11:33 xdt-hetter
At line one it replaced "nik" with "too" and the spelling of "Desktop" became "Desottt".
Why is this? What is logic behind it?
info coreutils 'tr invocation'tells you en detail whattrdoes. – Nephente Mar 17 '16 at 14:49nik-pcwithroot? – kos Mar 17 '16 at 14:51ns are translated tots instead ofrs as they should be.. Just to be sure, is there any chance you rantr "nik-pc" "toot"instead? – David Z Mar 17 '16 at 20:04nis also in thek-prange. The result of a character appearing more than once on the first set is unspecified by POSIX. – hmakholm left over Monica Mar 17 '16 at 20:35sedcommand...ls -l | sed 's/nik-pc/root/'would do what you want.tris for converting single characters - eg. lower-case to upper-case, or dos-style lineshift (\r) to Unix-style (\n), or something like replacing all backslashes (Windows) with slashes. It can also delete "unwanted" characters, eg. all numbers or all upper-case letters. – Baard Kopperud Mar 17 '16 at 23:26trreplaces the first set with the second, so "nik-pc" and "root" means that allnbecomesr, and i & k both becomes o, - becomes t... and I think p & c also becomes t (not sure though) – Baard Kopperud Mar 17 '16 at 23:31nwas in the range. – David Z Mar 18 '16 at 08:48