I have a file that needs to index and remove all duplicate variables (keeping the first of the duplicated). Then in another file, from the index I need to find and replace all those duplicated variables we deleted with their primary variable (the one we kept). I think this is a SED question, but if there are any better solutions I would greatly appreciate it.
Example:
newmtl m2
Kd 1.000000 1.000000 1.000000;
Ka 0 0 0
illum 2
Ns 64
d 1.000000
map_Kd 951E01Other4040.bmp
newmtl m3
Kd 1.000000 1.000000 1.000000;
Ka 0 0 0
illum 2
Ns 64
d 1.000000
map_Kd 951E01Other4040.bmp
newmtl m4
Kd 1.000000 1.000000 1.000000;
Ka 0 0 0
illum 2
Ns 64
d 1.000000
map_Kd 951E01Other4040.bmp
newmtl m5
Kd 1.000000 1.000000 1.000000;
Ka 0 0 0
illum 2
Ns 64
d 1.000000
map_Kd 951E01Other4040.bmp
Notice how m2, m3, m4, and m5 are the same. I need to delete m3, m4 and m5 and keep m2. Then in another file I have I need to find all variables m3, m4 and m5 and replace them with m2 because they no longer exist.
newmtl mXXX is the name and map_Kd is what determines if it is a duplicate. In this case we have map_Kd 951E01Other4040.bmp in others we have map_Kd A1C039w20h200x1CCOLORS.bmp and over 20 other meanings for map_Kd.
Hope I explained that in enough understandable detail. Let me know your thoughts.
Thank you!