Merge files using zipper method / late merge

mergetext processing

I am searching for a nice method of merging two or more files line by line using the zipper method (also called late merge). Assuming we have three files, the result should look like this:

line1 file1
line1 file2
line1 file3
line2 file1
line2 file2
line2 file3
...

EDIT

I wrote a little python script capable of doing this:

#!/usr/bin/python

import sys, itertools

fileList = []
for file in sys.argv[1:]:
    f = open(file, "r")
    fileList.append(f.read().split("\n"))

for z in itertools.izip_longest(*fileList):
    print "\n".join([i for i in z if i is not None])

I still wonder if there is any standard tool or a clever combination of them doing the same thing.

Best Answer

I usually use paste from coreutils for this sort of thing:

paste -d'\n' file1 file2 file3
Related Question