I have two CSV files in the following format:
First file:
GroupID, PID:TID, IP, Port
Sample data:
0,1000:11,127.0.0.1,445
0,-1:-1,127.0.0.1,800
1,1000:11,127.0.0.1,445
1,-1:-1,127.0.0.1,900
2,1000:11,127.0.0.1,445
2,-1:-1,180.0.0.3,900
Second file:
IP,Port,PID
Sample data
127.0.0.1,445,1000
127.0.0.1,800,1000
127.0.0.1,900,2000
What I need to do is as follows:
- in the first file, whereever I have PID as -1, I need to pick its IP and port and llok it up in 2nd file and replace the -1 PID with the PID from 2nd file
- Now based on the groupid (we are sure that there would be exacty 2 records with same group id), ignore all those groups where we have the same PID or if any PID is still -1 (ip port not found in 2nd file)
So in the above sample data:
first step will lead us to
0,1000:11,127.0.0.1,445
0,1000:-1,127.0.0.1,800
1,1000:11,127.0.0.1,445
1,2000:-1,127.0.0.1,900
2,1000:11,127.0.0.1,445
2,-1:-1,180.0.0.3,900
and the second step should get us the desired output
1,1000:11,127.0.0.1,445
1,2000:-1,127.0.0.1,900
We do not need the file after 1st step but that is just for explanation.