Using tr
command I want to convert Hello
into Hii
.
My command was:
$_="Hello";
print;
tr/Hello/Hi/;
print;
But the result was Hiiii
. What did I do wrong?
What is the right way to do it?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityTo replace Hello
by Hii
you could use:
s/Hello/Hii/
tr
works different. Using tr
both character sequences are handled as lists. The first character of the first list is replaced by the first character of the second list. So, H
is replaced by H
, e
is replaced by i
and so on.