The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
du from list with du of list total Movomito Shell Programming and Scripting 3 05-04-2008 06:33 PM
Comparing 2 list and deleting deuplicate entries eltinator Shell Programming and Scripting 10 08-15-2007 10:35 AM
how to generate a random list from a given list mskcc Shell Programming and Scripting 3 05-30-2006 12:30 AM
how to list dir only stephettt UNIX for Dummies Questions & Answers 2 02-22-2004 07:34 AM
Comparing data list... giannicello UNIX for Dummies Questions & Answers 4 03-06-2003 09:08 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-22-2004
Registered User
 

Join Date: Jun 2004
Location: KL
Posts: 7
Stumble this Post!
Comparing a distinct value in 1 list with another list

Hi all,

I need to compare the contents of 2 directories where the file contents are similar and take out the filenames whose contents does not exist within the 2 directories.

Directory1

1
2
3
4

Directory2

54
55
56
57

Does anyone has a script which can do this?
At the end of the command, all the files that does not exist when comparing the 2 directories should be cp -p to another new directory.

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-22-2004
joerg's Avatar
Registered User
 

Join Date: Jan 2002
Location: Germany
Posts: 167
Stumble this Post!
Hi!
you can use sdiff with the option -s to print only not identical lines.

ls -la /first_dir > 1.dir
ls -la /seconed_dir >2.dir
sdiff -s 1.dir 2.dir

I hope this help.
regards joerg
Reply With Quote
  #3 (permalink)  
Old 06-22-2004
Registered User
 

Join Date: Jun 2004
Location: KL
Posts: 7
Stumble this Post!
Hi Joerg,

Thanks for your advice, but the filenames are totally different, however the content is the same, in this case, how would i go about doing it?

There are 800+ files in one directory and 500+ in one directory, i know for sure that about 200+ do not share the same contents and i want to move them to another directory.

Regards,
Alvin
Reply With Quote
  #4 (permalink)  
Old 06-22-2004
joerg's Avatar
Registered User
 

Join Date: Jan 2002
Location: Germany
Posts: 167
Stumble this Post!
Is the timestamp of the file in side the first directory the same as in the second directory.
Please give us a output of the ls -la command for both directorys.
Which kind of contense it is?
regards joerg
Reply With Quote
  #5 (permalink)  
Old 06-22-2004
Registered User
 

Join Date: Jun 2004
Location: KL
Posts: 7
Stumble this Post!
Hi Joerg,

No the only thing that is the same is the xml file contents, i need to compare the file contents in one directory with the other directory. Do you know of a script which can do that?

Regards,
Alvin

s the timestamp of the file in side the first directory the same as in the second directory.
Please give us a output of the ls -la command for both directorys.
Which kind of contense it is?
regards joerg
Reply With Quote
  #6 (permalink)  
Old 06-22-2004
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Stumble this Post!
Loop thru files in source directory; see if file exists in destination; if it does then see if the contents differ...
Code:
#!/usr/bin/ksh

SOURCE=/path/to/source/dir
DEST=/path/to/dest/dir
cd $SOURCE
for i in *
do
    if [ -f $DEST/$i ]
    then
        echo file $i exists
        if cmp -s $i $DEST/$i
        then
            echo files are the same
        else
            echo files are different
        fi
    else
        echo file $i does not exist
    fi
done
Reply With Quote
  #7 (permalink)  
Old 06-22-2004
Registered User
 

Join Date: Jun 2004
Location: KL
Posts: 7
Stumble this Post!
Thanks for your help, i appreciate it but if the filenames which are different are over 200+ files, how do i automate this with diff to search through their contents in different directories?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0