1

I'm using cygwin for comparison count of files in 2 directories. I'm using this script:

a=$(ls //NSVA/Matrical/Vitesse/REPORTS | grep .csv | grep $1 | grep -v Pull | wc -l)
b=$(ls //10.9.214.200/Lims/LimsLZ/starlims1/done/Nitrostore_stored/$1 | grep -v Pull |wc -l)

echo "Count of Uploaded files in NS is $a" 
echo "Count of Uploaded files in LZ is $b"

if [ $a -eq $b ]; then
    echo "Count MATCH!";
else
    echo "Count does NOT MATCH!!!";
fi;

Now I have to compare files in $a and $b. They should be identical but it could be that $a has more or $b has more.

Could someone please advice how to do it?

I have an idea like re-direct it to e.g. $c and $d and than grep it and etc but I have an issue with syntax. I'd appreciate if someone could give me example of finding the difference of content between those two directories.

2

If you are trying to sync files, there is probably a better way (ie, rsync)

Anyway, given 2 directories with (mostly) the same content, you can use the diff utility. It will tell you which files only exist in one directory or the other, and it shows you a difference of the contents of the (plain text only) files that have matching (sub paths and) names.

ivan@darkstar ~ $ ls dir1 dir2
dir1:
a  b

dir2:
a  c
ivan@darkstar ~ $ diff dir1 dir2
diff dir1/a dir2/a
1c1
< aa00_processes_machine
---
> 00_processes_machine
Only in dir1: b
Only in dir2: c
ivan@darkstar ~ $ 
  • Thanks. I thought about it but you please continue ,y case with it? – susik Dec 22 '17 at 10:07
  • I have an issue with syntactic Thanks again. I mean add diff to my code – susik Dec 22 '17 at 10:09
  • Well in other words I can’t compare directories in my case because $a and $b are not directories but variable with a list of files. Either directories should be created and those files put there or still compare those two variables $a and $b. For some reason syntax does not work right for my case hence I would appreciate if someone could simply edit/modify my example. – susik Dec 22 '17 at 11:30
0

Well ... never mind my question because I resolved it myself. I was able to redirect the output of each variable in 2 files. Than I ran grep -vf and it worked for me. Thanks anyway..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.