bashcsvmuttcomm

Comparing two csv files using comm


I am working on a script that verifies differences between two csv files (file_1.csv and file_2.csv).

file_1.csv = tasks to be processed

file_2.csv = tasks already processed

For that, I wrote the following but it seems it doesn't work. Apparently the first "comm" command works but it is stuck at this stage.

if comm -3 file_1.csv file_2.csv;

then

mv file_1.csv file_2.csv
mutt -s "subject" -a file_1.csv -- somebody@domain.com < body_email.txt 
rm file_1.csv

else

exit

fi

The output of "if comm -3" is displayed in the prompt but I don't get the prompt back.

Can anyone please advise me what's wrong ?

Thanks !


Solution

  • You might want to sort the files before comparing, try:

    comm -23 <(sort -u file_1) <(sort -u file_2)

    this would give you all tasks that have not been processed

    For example, try the below code snippet:

    diff=`comm -23 <(sort -u file_1) <(sort -u file_2)`
    if [ $diff > 0 ]
    then
        cp file_1 file_2
        mutt -s "subject" -a file_1.csv -- somebody@domain.com < body_email.txt
        rm file_1.csv
    fi