DEV Community

Claus Guttesen
Claus Guttesen

Posted on

Check if value is present in all CSV-files

Hi. I often import CSV-files at work. Sometimes I need to know whether a value is present in a column in all files. Since I don't do that so often I usually just use the cut- and sort-command line utilities into temporary files. But it's boring. So I wrote a small utility called compare in Rust that can read one or more text-files, specify a column and delimiter and either see if a value is present in all files, or only in one.

Example using semicolon (;) as delimiter and column two (2) and in all set (i).

$ cat a.csv
1;a;one
2;b;two
3;c;three
4;d;four

$ cat b.csv
3;c;three
4;d;four
5;e;five
6;f;six

$ compare -f a.csv -f b.csv -d ';' -c 2 -o i
four
three

Can also be used to see what values that are present in only one set (s).

$ compare -f a.csv -f b.csv -d ';' -c 2 -o s

one
two
five
six

Source can be downloaded at https://github.com/kometen/compare.

Regards
Claus

Top comments (0)