Archive for November, 2019


Compare CSV files in Bash

I’ve been needing this forever!  I have huge CSV lists and have needed a way to quickly compare them.  For this I just need to make sure that the first field from one CSV does not exist anywhere in the second CSV.  It was actually pretty simple to write this in Bash and it runs really fast!

1
2
3
4
5
6
while IFS=, read -r field1 field2
  do
    if grep --F "$field1" list1.csv; then
      echo "$field1 found"
    fi
done < list2.csv

Permalink » No comments