Greg
Greg

Reputation: 1803

tr command not working as expected

I have the following string:

"Last updated Unknown </DIV> </DIV></DIV></TD></TR></TABLE></FORM></DIV></BODY></HTML>"

and I am trying a simple example to replace HTML with test but if I try this example I get a unexpected results:

echo "Last updated Unknown</DIV></DIV></DIV></TD></TR></TABLE></FORM></DIV></BODY></HTML>" | tr "HTML" "test"

Result:

tast updated Unknown </DIV> </DIV></DIV></eD></ eR></eABtE></FORs></DIV></BODY></test>

Upvotes: 0

Views: 2511

Answers (2)

Subbeh
Subbeh

Reputation: 924

tr is used to translate or delete characters. Try sed instead:

sed 's/HTML/test/g'

Upvotes: 3

timrau
timrau

Reputation: 23058

tr "HTML" "test" replaces H by t, T by e, M by s and L by t.

You could use sed instead.

$ echo "Last updated Unknown </DIV> </DIV></DIV></TD></TR></TABLE></FORM></DIV></BODY></HTML>" | sed 's/HTML/test/g'
Last updated Unknown </DIV> </DIV></DIV></TD></TR></TABLE></FORM></DIV></BODY></test>

Upvotes: 2

Related Questions