I have two files as shown below:
File 1 (tab delimited):
A1 someinfo1 someinfo2 someinfo3 A1 someinfo1 someinfo2 someinfo3 B1 someinfo1 someinfo2 someinfo3 B1 someinfo1 someinfo2 someinfo3
File 2 (tab delimited):
A1 newinfo1 newinfo2 newinfo3 A1 newinfo1 newinfo2 newinfo3 B1 newinfo1 newinfo2 newinfo3 B1 newinfo1 newinfo2 newinfo3
I want to read two lines together (lines starting with A1 and A1) from File 1 and two lines (lines starting with A1 and A1) from File 2. To be more clear, I have two requirements:
1) Reading two lines from the same file 2) Read same two lines from the other file.
To be precise, I want to read four lines together ( 2 consecutive lines from two files (2 lines from each file)).
I searched online and was able to get a code to read two lines together but only from one file.
with open(File1) as file1: for line1,line2 in itertools.izip_longest(*[file1]*2):
Also, I was also able to read one line from each of the two files as:
for i,(line1,line2) in enumerate(itertools.izip(f1,f2)): print line1, line2
But I want to do sth like:
Pseudocode:
for line1, line2 from file1 and line_1 and line_2 from file2: compare line1 with line2 compare line1 with line_1 compare line2 with line_1 compare line2 with line_2
I am hoping a solution to be a linear time one. All the files have same number of lines and the first column (primary id) is same for the consecutive lines within a file and the other file follows the same order (See the above example).
Thanks.