Skip to main content
3 of 7
added 612 characters in body
January
  • 2k
  • 2
  • 16
  • 14

Simply use paste:

cat file.in | paste - - -d, > file.out

The sed command replaces the numbers and dots at the beginning of the line. Explanation: 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 - (dash). 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.

Alternatively, do

cat file.in | sed "N;s/\n/,/" > file.out
January
  • 2k
  • 2
  • 16
  • 14