roc has asked for the wisdom of the Perl Monks concerning the following question:

file1.txt barra_id,cusip,tickers CAN1234,00234q,ABH.C CAN3245,0129ab,BCHD CAN342a,02032a,ABB
file2.txt bb_id,cusip,tickers 001E32,0129ab,BCHD 0023R2,00234q,ABH.C 023ER1,02032a,ABB
file3.txt tsx_id,cusip,tickers 91237q,02032a,ABB 92023w,00234q,ABH.C A12311,0129ab,BCHD
I want to compare all three files with respect to "cusip" and print tickers which compares "cusip", below is the example output,
output.txt cusip,file1_tickers,file2_tickers,file3_tickers 0129ab,BCHD,BCHD,BCHD 00234q,ABH.C,ABH.C,ABH.C

Replies are listed 'Best First'.
Re: compare:file records
by Narveson (Chaplain) on Feb 27, 2008 at 19:29 UTC

    Use a hash.

    And please format your sample files so others can easily read them. There's more than one way to do it, but personally I would just paste my files between code tags and then make sure the line breaks are where they belong.

    Here's an example of what I mean:

    file1.txt --------- barra_id,cusip,tickers CAN1234,00234q,ABH.C CAN3245,0129ab,BCHD
    etc.

    Then use the preview button and think about how the display will look to others. Help others see what your data looks like, and somebody may feel like offering more detailed advice.