You can easily do this with PHP, for example, you can read the CSV files into arrays and and compare the arrays:
Quick examples to get you started (untested, for example only):
<?php
$csvFile1 = file('../somefile.csv');
$csvarray1 = [];
foreach ($csvFile1 as $line) {
$csvarray1[] = str_getcsv($line);
}
$csvFile2 = file('../someotherfile.csv');
$csvarray2 = [];
foreach ($csvFile2 as $line) {
$csvarray2[] = str_getcsv($line);
}
Then you can use one or two of myriad PHP array methods to check for existence of keys, differences in arrays, etc. See, for example, these methods:
<?php
array_diff();
array_keys();
array_diff_ukey();
array_key_exists()
Then, after you have your new array as you desire, then you can simply convert your temporary array back to PHP, for example:
<?php
fputcsv ();
In a nutshell, is easy to process CSV files with PHP either from a script, directly from the command line, or interactively from the command line; most notably converting CSV files to arrays, doing array operations, and converting back to a CSV file.
So personally I would do this in PHP and not use shell scripts because PHP is built to do this kind of processing easily.
OBTW, these days I tent to quickly prototype and test my PHP ideas interactively in the shell as follows:
php -a
Then in the shell in interactive mode, I test and debug logic quickly and easily.
This is how I process CSV files. You can also easily to this same type of CSV processing easily in Python, BTW.
Other may have more "shell script-like" approaches for you which do not use PHP or Python; I am only describing how I approach these types of issues in CSV, JSON or other standard file formats. Since most of my work all touches the Internet somehow (web servers), and those servers are mostly PHP based, I like to stick to code I can reuse and debug together, so that is why I tend to use PHP over Python. Actually, if my apps were not mostly PHP based, I would use Python more.