1832689 Members
2831 Online
110043 Solutions
New Discussion

Re: about command:tr

 
iambluegary
Advisor

about command:tr

i cant understand the function of the command tr,for example
there is a file:one
in it:
ie
iei
ieie
i am a boy

when a use command:
tr "[=e=]" "[e*]" two
then i look at file:two
it is the same as one,i dont know what happened
help ,help,help :-)
6 REPLIES 6
Paula J Frazer-Campbell
Honored Contributor

Re: about command:tr

HI

This may help:-

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x061672106351d5118fef0090279cd0f9,00.html



Paula
If you can spell SysAdmin then you is one - anon
Stefan Schulz
Honored Contributor

Re: about command:tr

Hi,

could you please tell us what you tried to accomplishe?

I can't figure out what result you tried to get.

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Ralph Grothe
Honored Contributor

Re: about command:tr

Have you read the manpage of tr?

It translates (or in Perl-Lingo transliterates) each character of the first character set exactly with the one from the second character set.
Madness, thy name is system administration
Deepak Extross
Honored Contributor

Re: about command:tr

The output is identical to the input because there is *nothing* to translate.
Your input does not have any accented variants of the charcter 'e' (e-umlaut, e-ascent, e-grave', etc).
Shannon Petry
Honored Contributor

Re: about command:tr

May be worth reading on regular expressions for a better understanding. I have the O'Reilly book on sed/ed and it has lots of good info on reg-expressions. I think tr will make much more sense when you see how they work.

Regards!
Shannon

> echo "Mjdsptpgt Sudlt"|tr "[b-t]" "[a-s]"
Microsoft. When do you want a virus today?
SHABU KHAN
Trusted Contributor

Re: about command:tr

Hi,

tr gets its input through a pipe, try:

cat filename | tr "[=e=]" "[e*]" > test.out


I usually use "tr" to trim the spaces/tabs, It is a very handy command ...

To parse files with uneven spaces between fields

cat filename | tr -s " "

will trim the spaces to just one space between the fields...

cat filename | tr -s "\t" " "

will trim tabs and spaces between fields to just one space ...



Thanks,
Shabu