Sample Header Ad - 728x90

Comparing csv files to lookup column 1 then check values in column 2

2 votes
3 answers
5760 views
OK, I will try and explain what I need to do as best as possible. Basically I have two CSV files, as per the examples below: File 1: Column 1, Column 2 abc , 123 def , 234 adf , 567 File 2 Column 1, Column 2 abc , 123 def , 234 adf , 578 I need to write either a shell script or simple command that will do the following: 1. Sort both files by column 1 2. Row by row, do the following: - Using column 1 in file 1, search for this value in column 1 in file 2. 1. if found, compare the value in column 2 in file 1 against the value in column 2 of file 2 1. if it matches, write column 1, column 2 and "Validated" in column 3 to a separate file 1. if it does not match, write column 1, column 2 and "Failed" to a separate file This results in two output files: the first with everything that was found in column 1 and column 2 matches, and a second file containing either column 1 lookups that failed or where column 1 was found, where column 2 did not match, so, essentially, using column 1 as the key to check column 2.
Asked by Veyron (29 rep)
Mar 21, 2017, 05:08 PM
Last activity: Apr 27, 2025, 07:05 PM