tr command

Hi all,

man tr says
tr [OPTION]... SET1 [SET2]
SETs are specified as strings of characters

I did not understand the terms " strings of characters"

when I surfed the net I got some examples like
tr -d '\015' file1

Does \015 is string of characters or '\015' is string of characters.
Basically I want to know the definition of string .

In the page How to use the tr command, by The Linux Information Project (LINFO)

It mentions that ,tr can also translate any number of specified characters into other characters. In such case, each of the two sets needs to be enclosed in square brackets, and these brackets, in turn, need to be enclosed in quotation marks. Either single of double quotation marks can be used.
I had seen example
tr -d '\015' file1
working fine with out quotes or double quotes.

Can somebody tell me what exactly the input format for tr.

Thanks in Advance

string is collect of charakters, can be only one character
OK?
can do:

tr -d '\015\080' file

or

tr -d 'acd' file

I think, your shall sey you what use "" or ''.

some examples of usage:

change one letter:

#  echo hello world | tr -s "h" "k"
kello world

change two

#  echo hello world | tr -s "hl" "kf"
kefo worfd

more powerful:

#  echo hello world | tr "[a-z]" "[A-Z]"
HELLO WORLD

can specify shorter lists:

#  echo hello world | tr "[a-g]" "[A-G]"
hEllo worlD

remember, each letter gets translated for pos_string_1 to pos_string_2:

#  echo hello world | tr "[a-g]" "NGHRTYE"
hTllo worlR

deleting:

#  echo hello world | tr -d "l"
heo word

squeezing:

#  echo hello world | tr -s "l" "X"
heXo worXd

also - "man ascii" "\015 defines a single character"

HTH

Hi

Below are my experiments

1.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'" | tr "\'" 't'
hiit
2.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'" | tr "'" 't'
hiit
3.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'" | tr "[']" 't'
hiit
4.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'" | tr "[[']" 't'
hiit
5.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'" | tr "[\[']" 't'
hiit
6.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'[" | tr "['[]" 'ta'
hiiaa
7.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'[" | tr "[']" 'ta'
hiiat
8.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'[" | tr "[']" 'ta'
hiiat
9.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'" | tr "[']" 'ta'
hiia
10.[root@HP-BL3-CONXIP-VM6 log]# echo "hii'" | tr "[']" 't'
hiit

Observe case 9 and case 10 .
So somebody can point me the link where the implementation of tr command.

I do not think the information on that page is correct:

$ echo 'abcdefgh' | tr '[efg]' '[xyz]'
abcdxyzh
$ echo 'abcdefgh' | tr 'efg' 'xyz'
abcdxyzh
$ echo 'abcdefgh' | tr efg xyz
abcdxyzh

There is no need for square brackets; they are a.o. used for ranges.

From the man page:

So in example 9, [ is mapped to t, ' is mapped to a and ] is also mapped to a.
In example 10, [ is mapped to t, ' is mapped to t and ] is also mapped to t.