2

I have a string animal: dog and I would like to transform to have just animal dog (one space between).

e.g:

echo 'animal: dog' | tr ':' ' '
animal  dog

There's 2 spaces above.

I tried making the replace an empty string but:

echo 'animal: dog' | tr ':' ''
tr: when not truncating set1, string2 must be non-empty

I can get desired outcome with -s but then I have to call tr twice. Is there a way to do it in a oner?

echo 'animal: dog' | tr ':' ' ' | tr -s ' '
animal dog
Doug Fir
  • 133
  • 1
  • 5

1 Answers1

4

Use the -d option. echo animal: dog | tr -d : outputs animal dog.

don_aman
  • 1,373