Help with joining two files
Greetings, all. I've got a project that requires I join two data files together, then do some processing and output. Everything must be done in a shell script, using standard unix tools. The files look like the following:
File_1
Layout:
Acct#,Subacct#,Descrip
Sample:
0001,0001,Account1/Sub1
0001,0002,Account1/Sub2
0002,0001,Account2/Sub1
0002,0002,Account2/Sub2
0002,0003,Account2/Sub3
...
File_2
Layout:
TransID,Code,Acct#,SubAcct#,Date,To,For,Amount,Ref#
Sample:
1,D,0002,0001,2006-01-03,Joe,Services,35.00,1234
2,C,0002,0003,2006-01-05,Mary,PC Repair,50.00,
3,D,0001,0001,2006-01-05,Amazon.com,book,39.95,1235
...
In essence, I need to add the proper description from File_1 into each record of File_2. Once the join is complete, I plan on using awk to summarize the data and output, so order is not important (description can go in right after the acct# & subacct# columns in File_2, or it can be appended to the end of each line).
I've tried join already, but since join expects to match on a single field, and I'm trying to match on two fields, join hasn't been much help. I've also tried sed, but I can't seem to get the replacement syntax right.
Any help would be greatly appreciated.
Rich Lohman