Q:

paste command shell not joining all lines

I have a file with contents as shown in multiple lines:
aa 
bb
cc
dd
And I want to merge all lines in a single line using paste command. While Using  "paste -s file" command on the terminal I am getting the output as: aa     dd i.e. only first line and last line is getting printed. I dont know what's going wrong in this paste command.
How to correct this so that I can merge all lines in a single line such that I can get the output on terminal as:  aa bb cc dd ?

A:

You can get everything on one line wuth spaces by using
echo file | tr "\n" " " | sed 's/ $/\n/'

You can fix windows files with tr too:
echo file | tr -d "\r" | tr "\n" " " | sed 's/ $/\n/'

