Identify matching data in a file and output to original line, in perl
Hi,
I haven't done this for awhile, and further, I've never done it in perl so I appreciate any help you can give me.
I have a file of lines, each with 5 data points that look like this:
AB,N,ALLIANCEBERNSTEIN HLDNG L.P,AB,N
ALD,N,ALLIED CAPITAL CORPORATION,ALD,N
AFC,N,ALLIED CAPITAL CORPORATION,ALD,N
Let's call it: a,b,c,d,e
Every time a == d and b == e, I want to then search every other line in the file and find where a == d(newline) and a == e(newline). Whenever this is the case, I want to append the a,b data from the newline to the original line such that it reads: a,b,c,d,e,a(newline),b(newline).
Using the data above, we would output something like this:
AB,N,ALLIANCEBERNSTEIN HLDNG L.P,AB,N
ALD,N,ALLIED CAPITAL CORPORATION,ALD,N,AFC,N
AFC,N,ALLIED CAPITAL CORPORATION,ALD,N
I'm also not sure how many total matches there might be in the file so I could end up with ~100 matching lines for any original line such that the final result for the original line would look like: a,b,c,d,e,a(newline0),b(newline0)...,a(newline100),b(newline100)
Does that make sense?