I have two pipe delimited files
File1.txt
f1|f2|f3|f4|
123456|C|aws|zip|
589445|D|csv|zip|
789466|C|txt|tar|
874512|A|row|war|
File2.txt
f1|f2|f3|f4|
458788|C|aws|zip|
589445|D|||
789466|C|wd|rar|
458745|A|xls|rar|
Final.txt
123456|C|aws|zip|
789466|C|wd|rar|
874512|A|row|war|
458745|A|xls|rar|
1.Take the field f2 from File2, if it is D, take corresponding field f1 from File2 and identify the corresponding row matching to the field f1 in File1 and delete the row from File1. Same way
2.Take the field f2 from File2, if it is C, take corresponding field f1 from File2 and identify the corresponding row matching to the field f1 in File1 and replace the row in File1 with corresponding line in File2.
2.Take the field f2 from File2, if it is A, directly add the row to the File1 as new row.