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 and shell scripting languages 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 10:33 PM
Comparing 2 list and deleting deuplicate entries eltinator Shell Programming and Scripting 10 08-15-2007 02:35 PM
how to generate a random list from a given list mskcc Shell Programming and Scripting 3 05-30-2006 04:30 AM
how to list dir only stephettt UNIX for Dummies Questions & Answers 2 02-22-2004 11:34 AM
Comparing data list... giannicello UNIX for Dummies Questions & Answers 4 03-06-2003 01:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-22-2004
manualvin manualvin is offline
Registered User
  
 

Join Date: Jun 2004
Location: KL
Posts: 7
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.
  #2 (permalink)  
Old 06-22-2004
joerg's Avatar
joerg joerg is offline
Registered User
  
 

Join Date: Jan 2002
Location: Germany
Posts: 167
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
  #3 (permalink)  
Old 06-22-2004
manualvin manualvin is offline
Registered User
  
 

Join Date: Jun 2004
Location: KL
Posts: 7
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
  #4 (permalink)  
Old 06-22-2004
joerg's Avatar
joerg joerg is offline
Registered User
  
 

Join Date: Jan 2002
Location: Germany
Posts: 167
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
  #5 (permalink)  
Old 06-22-2004
manualvin manualvin is offline
Registered User
  
 

Join Date: Jun 2004
Location: KL
Posts: 7
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
  #6 (permalink)  
Old 06-22-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
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

  #7 (permalink)  
Old 06-22-2004
manualvin manualvin is offline
Registered User
  
 

Join Date: Jun 2004
Location: KL
Posts: 7
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?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0