I have two files "1.txt" and "2.txt".
The structure of both the files is :
Main_File1 Start End
1 200 250
2 310 340
Main_File2 Start End
1 200 250
2 350 370
I want to write a perl code for which the output should be two files i.e. one file having the list of common "start" and "end" positions and other file having unique "start" and "end" positions.
I'm going to guess you already have code for reading each of these files, and just need to parse out the values and organize them.
The design part is coming up with a key that is unique for each start,end pair, but not hard to work with. Since start and end are numbers, this should be pretty easy:
So here we make a key which is
start_end
, and then we build a data structure inside the hash which is an array of two elements. The first element is the original line, the second is the count of how many times we've seen this entry.If a line is unique, the count will be
1
; if it's not, then it will be greater than1
.