Operating System - Linux
1751832 Members
5312 Online
108782 Solutions
New Discussion юеВ

Re: tr command (for strings)

 
SOLVED
Go to solution
Manuales
Super Advisor

tr command (for strings)

hi !!
how can i use tr command but with strings .. i have checked online man but it says we must use files .. i need to use tr command to strings, how can i use it?

thanks, Manuales.
3 REPLIES 3
john korterman
Honored Contributor
Solution

Re: tr command (for strings)

Hi,

you can pipe input to tr as std. in, e.g.:

# echo "text" | tr "[:lower:]" "[:upper:]"

# echo "text" | tr "x" "s"

regards,
John K.
it would be nice if you always got a second chance
James R. Ferguson
Acclaimed Contributor

Re: tr command (for strings)

Hi Manuales:

For example:

# echo "aaabc"|tr -s "a"

This is nothing more than using STDIN as the file for 'tr' processing. All well-behaved UNIX filters operate this way.

Regards!

...JRF...
Arturo Galbiati
Esteemed Contributor

Re: tr command (for strings)

Hi,
you can use each command shows the contenet of the string: echo, print, printf piping the output to tr.

i.e.:
echo "abc"|tr -d "b"
print "abc"|tr -s "b" "B"

string="abc"
echo $string|tr -d "b"

HTH,
Art