Hi Forum,
I hope you can help me troubleshoot as to why the following command is not working as expected. I want to replace the first column from org_file.dat with the second column from lookup_file.dat if the first column in both files match:
I have the following 2 csv files:
org_file.dat:
2210280,01/30/2023 17:42:38,01/30/2023 00:00:00,50.0000000000,DR,SWING,SAV,Withdrawal,N/A,557.6000000000,2211,,
5732284,01/30/2023 23:30:44,01/30/2023 00:00:00,45.0000000000,DR,NSFRET,NSF - EFT Withdrawal,N/A,531.7300000000,5536,,
11371406,01/30/2023 15:57:10,01/30/2023 00:00:00,309.3500000000,CR,DDIEMTC,DDA Deposit - E-Mail,N/A,618.3100000000,2024,,
12237880,01/30/2023 22:35:58,01/30/2023 00:00:00,420.0000000000,CR,SDMRDC,SAV Deposit - Mobile Remote Deposit,N/A,69282.7500000000,641,,
lookup_file.dat:
12237880,123
11371406,456
5732284,789
2210280,890
Desired Output:
890,01/30/2023 17:42:38,01/30/2023 00:00:00,50.0000000000,DR,SWING,SAV,Withdrawal,N/A,557.6000000000,2211,,
789,01/30/2023 23:30:44,01/30/2023 00:00:00,45.0000000000,DR,NSFRET,NSF - EFT Withdrawal,N/A,531.7300000000,5536,,
456,01/30/2023 15:57:10,01/30/2023 00:00:00,309.3500000000,CR,DDIEMTC,DDA Deposit - E-Mail,N/A,618.3100000000,2024,,
123,01/30/2023 22:35:58,01/30/2023 00:00:00,420.0000000000,CR,SDMRDC,SAV Deposit - Mobile Remote Deposit,N/A,69282.7500000000,641,,
This is the awk command that I ran but I'm not getting the expected results:
awk -vOFS="," 'NR==FNR{a[$1]=$2; next}{$1=a[$1]; print}' lookup_file.dat org_file.dat
Thank you for your time and feedback.