A case for “paste” instead of “tr” to replace newlines with spaces

Let's say I'm doing something that outputs stuff one item per line to the stdout:

foo@bar:~$ dpkg -l | grep sasl | awk '{print$2}' 
libsasl2-2
libsasl2-modules

Let's say I want to replace newlines with spaces.

Using "tr" works, but messes up the console:

foo@bar:~$ dpkg -l | grep sasl | awk '{print$2}' | tr '\n' ' '
libsasl2-2 libsasl2-modules foo@bar:~$ 

Using "paste" works as well, and doesn't mess up the console:

foo@bar:~$ dpkg -l | grep sasl | awk '{print$2}' | paste -sd' '
libsasl2-2 libsasl2-modules

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).