Multi-line output to single line

Hello,

How can I take the following output:

outputa
outputb
outputc

and turn it into single line ouput, with a single space between each field like below:

outputa outputb outputc

presume this is the output from a script. You can change your script to display in the same line instead of printing in the newline.
Eg :-

echo "outputa\c "
echo "outputb\c "
echo "outputc"

'\c' in the above echo will make sure next echo to print in the same line.

correct, but you may have to use -e option with echo to get the \c interpreted.

-ilan

am on solaris and using Bourne shell which doesn't require '-e' option :slight_smile:

Mani, thanks again for correcting me; i am not much aware of Solaris.

have a look at the man page for tr.

What you probably want here is:

tr "\n" " " < infile

Thanks for all the replies. I also ended up finding this solution that fit:

awk -v x="" '{ s=s sprintf(x "%s" x " ", $0) } END { sub(",$", "", s); print(s) }' file.txt

Hi,
Sorry for the late reply
Try This Out!!!!!!!!!!!!!!!!!

awk 'BEGIN{FS="\n"}{printf "%s",$1 " "}' filename

Regards