What’s an easy way to merge multiple rows into single rows? For example, if I have the following:

$cat file

A

B

A

B

A

B

How can I convert this into:

A B

A B

A B

$awk '{total=total" "$0}NR%2==0{print total; total=""}' file

I want to be able to merge various numbers of rows into single. In the

above example, it’s 2 rows being merged into 1 but what if I need to

merge 3 into 1, such as the following:

A

B

C

A

B

C

to be converted to the following:

A B C

A B C

$awk '{total=total" "$0}NR%3==0{print total; total=""}' file