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

Re: Comparing files in two directories



On 6/15/07, William Pursell <bill.pursell@gmail.com> wrote:
L.V.Gandhi wrote:
> On 6/14/07, *William Pursell* <bill.pursell@gmail.com
>     L.V.Gandhi wrote:
>      > On 6/14/07, *William Pursell* < 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

>
> 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"

I don't understand what you are trying to filter out here.  /^5,/d
will remove all lines that start with "5,".  I don't understand how
that is useful here.

<output snipped>
> 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

Here, you need to set IFS.  Also, in the first line of diffsum,
INSERTED gets the text string "INSERTED" rather than an integer value.  Try:
sed -n '2,$p' diffsum | (IFS=','; while read INSERTED DELETED MODIFIED
FILENAME; do if test $INSERTED -gt 0; then echo $FILENAME;fi;done )



> 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.

I like that.  Your invocation of sed is cleaner than mine...
Even better would be:
for line in $(sed 1d diffsum); do...

In this last one, your problem is a simple typo.  replace
"insert" with "$insert"



Thanks for the help.

--
L.V.Gandhi
http://lvgandhi.tripod.com/
linux user No.205042
Reply to: