[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Comparing files in two directories



On 6/14/07, William Pursell <bill.pursell@gmail.com> wrote:
L.V.Gandhi wrote:
> On 6/14/07, *William Pursell* <bill.pursell@gmail.com
> <mailto:bill.pursell@gmail.com>> wrote:
>
>     L.V.Gandhi wrote:
>      > I have two directories A and B. In each directory, I have nearly 1000
>      > files with same names. I would like to compare both directories
>     and find
>      > out which files differ more than say 5 lines. I use kompare and see
>      > manually. How to do it in command line easily?
>
>     Here's a scriptlet that will print the name of all the files for
>     which diff produces more than 5 lines of output.  (Which is not quite
>     to say that they differ in 5 lines, but it's close).
>
>     for file in $(find A -type f); do if test $(diff $file B/${file/A/} | wc
>     -l) -gt 5; then echo $file; fi; done
>
>
> Can you please explain both $ part?

$(find A -type f) produces a list of files in the directory A.

${file/A/} produces the file name with the leading "A" deleted,
eg:"A/foo" becomes "/foo"

$file B/${file/A/} becomes "A/foo B//foo" which is the
argument list to diff.
I tried your script in little modified wayas follows
rm -f temp;for file in $(find datafiles -type f); do if test $(diff $file datafiles2/${file/datafiles/} | wc -l) -gt 5; then echo $file >> temp; fi; done
where directories compared are datafiles and datafiles2
it gave output of
lvgandhi@lvgvaio:~$ cat temp|wc -l
1113
Files in datafiles are
lvgandhi@lvgvaio:~$ ls -l datafiles/* |wc -l
1131
But using diff and diffstat as
diff datafiles  datafiles2 >difffile
diffstat -v -t difffile -o diffsum
lvgandhi@lvgvaio:~$ cat diffsum| sed "/^5,/d"|sed "/^4,/d"|sed "/^3,/d"|sed "/^2,/d"|sed "/^1,/d"
INSERTED,DELETED,MODIFIED,FILENAME
816,816,0,BOSCHCHASY
739,739,0,MAX
833,833,0,MIRZAINT
267,267,0,NANDAN
812,812,0,SUVEN
Have I misunderstood you in using your script?
Instead of cat diffsum| sed "/^5,/d"|sed "/^4,/d"|sed "/^3,/d"|sed "/^2,/d"|sed "/^1,/d",
I tried
while read INSERTED DELETED MODIFIED FILENAME;do if [ $INSERTED -gt 5 ];then echo $FILENAME;fi;done < diffsum
I get error
bash: [: 5,5,0,3IINFOTECH: integer _expression_ expected
I also tried
for line in $(cat diffsum|sed "/FILENAME/d");do insert=$(echo $line|cut -d, -f1);symbol=$(echo $line|cut -d, -f4);if [ insert -gt 5 ];then echo $symbol;fi;done
Still I got
bash: [: insert: integer _expression_ expected
What to do to correct these errors.
--
L.V.Gandhi
http://lvgandhi.tripod.com/
linux user No.205042
Reply to: