LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-22-2007, 03:46 AM   #1
sharathkv25
Member
 
Registered: Jul 2006
Distribution: HP-UX
Posts: 46

Rep: Reputation: 15
Recursive diff ( File compare ) script


Hi,

I wrote a small script to compare 2 same files in 2 different repositories(say build1 & build2).

This is my script
Code:
SRC_DIR=/home/otroot/sharath/SQLJ_Daemon
TARGET_DIR=/home/otroot/sharath/ICS

for i in `ll -R "$SRC_DIR" | awk '{print $9}'`
do
   if [ "$i" != "" ];
   then
       for j in `ll -R "$TARGET_DIR" | awk '{print $9}'`
       do
          if [ "$j" != "" ];
          then
              if [ "$i" = "$j" ];
              then
                   echo "Comparing files $i    $j"
                   diff -cw $i $j
               fi
          fi
       done
   fi
done
This is the output I am getting.
Code:
Comparing files DB    DB
Comparing files TPICS    TPICS
No differences encountered
Comparing files ics.fmx    ics.fmx
diff: input file ics.fmx: No such file or directory
Comparing files ICSDaemon.class    ICSDaemon.class
diff: input file ICSDaemon.class: No such file or directory
Comparing files ICSDaemon.java    ICSDaemon.java
diff: input file ICSDaemon.java: No such file or directory
Comparing files ICSDaemon.sqlj    ICSDaemon.sqlj
diff: input file ICSDaemon.sqlj: No such file or directory
Comparing files TPSession.class    TPSession.class
diff: input file TPSession.class: No such file or directory
Comparing files TPSession.java    TPSession.java
diff: input file TPSession.java: No such file or directory
Comparing files TPSession.sqlj    TPSession.sqlj
diff: input file TPSession.sqlj: No such file or directory
Comparing files TPSessionCxt.class    TPSessionCxt.class
Any idea why I am getting "diff: input file <filename>: No such file or directory" here?
 
Old 02-22-2007, 05:19 AM   #2
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
You will be getting only the filename there , not the full patch with the directory.
So it says "Not able to find file"

Instead of
ll -R "$TARGET_DIR" | awk '{print $9}'

try

find "$TARGET_DIR" -type f

This should work

But the loop can be optimized a bit. :>
 
Old 02-22-2007, 05:23 AM   #3
Nick_Battle
Member
 
Registered: Dec 2006
Location: Bracknell, UK
Distribution: SUSE 13.1
Posts: 159

Rep: Reputation: 33
Yes, you need to use full pathnames, but... diff has an option to recursively diff two root directories doesn't it? Just diff dir1 dir2.
 
Old 02-22-2007, 05:30 AM   #4
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
Yeah its

diff -r dir1 dir2

Thats a easier one
 
Old 02-22-2007, 06:23 AM   #5
sharathkv25
Member
 
Registered: Jul 2006
Distribution: HP-UX
Posts: 46

Original Poster
Rep: Reputation: 15
Hi,

I knew about "diff -r".However what if the directory structure has been reorganized between 2 builds?

Any easier method to compare the same file,but in 2 dissimilar directory structure?
 
Old 02-22-2007, 09:39 AM   #6
Nick_Battle
Member
 
Registered: Dec 2006
Location: Bracknell, UK
Distribution: SUSE 13.1
Posts: 159

Rep: Reputation: 33
Quote:
Originally Posted by sharathkv25
I knew about "diff -r".However what if the directory structure has been reorganized between 2 builds?
I think diff on dirs will only compare files of the same name if they're in the same subdirectory. If you know they've moved (and the names are unique in the tree) your method is reasonable, though it would be better driven by find(1) than ls -lR.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to compare file size nazs Programming 6 05-24-2006 11:10 AM
mass file compare or diff mijohnst Linux - Software 11 01-27-2006 07:32 AM
Diff compare 2 files DavidTempler Linux - Newbie 2 11-01-2004 11:00 AM
Using diff to compare file with common lines, but at different line numbers jimieee Linux - Newbie 3 05-10-2004 08:26 AM
How Compare FS/dirs - can't use 'diff'? MikHud Linux - General 2 05-07-2002 08:51 AM


All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration