|
File Merging Problem
i have 3 files
a.txt , b.txt and c.txt
each files have keyfields and some column fields
e.g.
a.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3
1 2 3 44 55 66
4 5 6 92 48 33
.....................etc..................
b.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4
1 2 3 44 55 66 78
4 5 6 92 48 33 99
.....................etc..................
b.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
7 8 9 447 255 366 678 25
4 5 6 92 48 33 97 43
1 2 3 44 55 66 78 88
.....................etc..................
key fields are the primary keys to these above files
here 1 st key is 123then
script will check a.txt's col1,col2,col3 to b.txt's col1,col2,col3 and c.txt's col1,col2,col3
for the key field 123
here all values are equal for key field 123 if not matches then script will exit for further checking telling that for key field 123 initial matches are not OK .
so it will append result.txt
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66
then since b.txt and c.txt have some extra columns col4 and col5
so it will check col4 of b.txt with col4 of c.txt
if it matches then matching value will be there if not matching then nonmatch vales separted by comma will be thereso result.txt will be
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78
here col5 is the extra column in c.txt for the same keyfield 123, so simply this will be placed as col5
so result.txt will be
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
similary for keyfiled 456 result.xtx will be
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
4 5 6 92 48 33 99,97 43
if any file has extra line(s) and has no matches to any files then it will simply append into the result.txt
so final result.txt will be
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
4 5 6 92 48 33 99,97 43
7 8 9 447 255 366 678 25
i am not sure, whether i expalined my situtaion prperly or not. but please let me know if it's not.
but if so, then kindly let me know how to achieve this ????
NOTE: Ther might be n number of columns..depends on the requirement . So script should accumulate such number of columns dynamaically .
Last edited by manas_ranjan; 06-20-2008 at 11:53 AM..
|