cat (if you like cats ;-)) and
cat file.in | paste -d, - - > file.out
paste reads from a number of files and pastes together the corresponding lines (line 1 from first file with line 1 from second file etc):
paste file1 file2 ...
Instead of a file name, we can use
paste takes first line from file1 (which is stdin). Then, it wants to read the first line from file2 (which is also stdin). However, since the first line of stdin was already read and processed, what now waits on the input stream is the second line of stdin, which
paste happily glues to the first one. The
-d option sets the delimiter to be a comma rather than a tab.
cat file.in | sed "N;s/\n/,/" > file.out
P.S. Yes, one can simplify the above to
< file.in sed "N;s/\n/,/" > file.out
< file.in paste -d, - - > file.out
which has the advantage of not using
However, I did not use this idiom on purpose, for clarity reasons -- it is less verbose and I like
cat (CATS ARE NICE). So please do not edit.
Alternatively, if you prefer paste to cats (paste is the command to concatenate files horizontally, while cat concatenates them vertically), you may use:
paste file.in | paste -d, - -