another trim question using tr

Hi all,

I've been looking for how to eliminate blank spaces in a variable or strings. I've seen several ways, using sed, awk and even python. One of them is use 'tr' command, but it does not work as I expected: For example:

echo "     stuff      " | tr -s " "

leaves one space ahead and another behind. Why?
I also tried

echo "     stuff      " | tr -d " "

and it works successfully. However, all samples I've seen with "tr", use -s option (which I guess it means replace) rather than -d option.
I'd like to know why.

Thanks a lot.

Albert.

Albert, u can use the below. Works on bash and ksh.

 
echo "     stuff      " | tr -d [:space:]

HTH,:cool:

Regards,

Praveen

Thanks sunpraveen, although it is not exactly what I asked for :confused:. However, it does help :D!!!

Albert.

-d Delete all occurrences of input characters that are specified
-s Replace instances of repeated characters with a single character

Delete vs replace by a single char.

Did you try "-ds" ? :smiley: