Is it possible to print the awk output in the same line

Issue

The awk output looks like:

awk '{print $2}'
toto
titi
tata

I want to dispay the output of awk in the same line with space as separator instead of new line

awk [option] '{print $2}'
toto titi tata

Is it possible to do that?

Solution

From the manpage:

ORS         The output record separator, by default a newline.

Therefore,

awk 'BEGIN { ORS=" " }; { print $2 }' file

Answered By – Manny D

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published