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