Sample Header Ad - 728x90

Comparing two .csv files and write into 3rd file

0 votes
4 answers
1936 views
On my Mac I have two files: file1.csv (about 4000 rows) 1234,yxds 4352,fsfk 8765,fdgj 7874,hffe 9038,fjro 8297,fhjs and file2.csv (about 50 rows) 1234,"number","date","OS" 4352,"number","date","OS" 8765,"number","date","OS" 8297,"number","date","OS" file 3 should look like this: 1234,yxds 4352,fsfk 8765,fdgj 8297,fhjs So I only want the entries that exist in file2.csv but with column 2 of file1.csv Essentially I want to write a script compares file1.csv to a different file3.csv So far I tried join and awk but with no success. This is what i tried so far : join -t, -12 -o 1.1,2.1,2.2 file1.csv file2.csv > file 3.csv and awk 'NR==FNR{a[$1]=$2;next}{if ($1 in a && a[$1] != $2)print;}' FS="|" file1.csv file2.csv > file3.csv
Asked by Sotey (1 rep)
Jun 11, 2019, 09:59 AM
Last activity: Jul 21, 2023, 07:02 AM