I must say I like the
xargs solution. Clever. I'd skip
cat though and use a shell redirection.
Code:
xargs -n2 <infile.txt
However, here's yet another option for you:
Code:
sed 'N;s/\n/ /' infile.txt
You can concatenate 3 or more lines together with additional
N commands and the
g flag to the substitution. And the
-i option (assuming
gnu sed) can be used to return the edits directly to the input file.
Code:
sed -i 'N;N;s/\n/ /g' infile.txt
Finally, here's a quick bash-only solution that will work as long as the input isn't too large and you're using v.4+. It should be very fast on small files.
Code:
mapfile -t nums <infile.txt
printf '%s %s\n' "${nums[@]}"