The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
need some help..Comparison bluesilo Shell Programming and Scripting 0 02-23-2008 04:43 PM
Timestamp comparison zainravi Shell Programming and Scripting 1 01-21-2008 08:28 AM
Unix comparison NewGuy100 UNIX for Dummies Questions & Answers 1 12-14-2005 04:42 PM
comparison problem ranj@chn Shell Programming and Scripting 8 11-05-2005 07:03 AM
comparison cnf Filesystems, Disks and Memory 2 05-14-2002 01:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 1.00 average. Display Modes
  #1 (permalink)  
Old 12-20-2004
ghazi ghazi is offline
Registered User
  
 

Join Date: Dec 2004
Posts: 15
dir comparison help

How do I find a duplicate files in two directories:

scenerio:

dirA:
file1
file2
file3

dirB:
file1
file4
file5
file6

file1 is residing at both locations while should be only at dirA.

ll /test/dirA | cut -c 59-80 > /test/dirA/files_at_dira
ll /test/dirB | cut -c 59-80 > /test/dirB/files_at_dirb

for file in /test/dirA/files_at_dira
do
grep $file /test/dirB/files_at_dirb
if $? = 0
then
echo "duplicate file $file found at /test/dirB/"
rm -i $file /test/dirB/
else
"duplicate file not found"
fi
done

Can some one please help on this.

Thank you in advance.
Ghazi
  #2 (permalink)  
Old 12-20-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try the dircmp command. Type "man dircmp".
  #3 (permalink)  
Old 12-20-2004
ghazi ghazi is offline
Registered User
  
 

Join Date: Dec 2004
Posts: 15
Thanks for your reply but I wanted to set up some kind of
automated script via cron which makes the two dir in sync on regular basis.

dircmp displays dirA and dirB in tabulated form.
I tried with both -d option but does not help.
  #4 (permalink)  
Old 12-20-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Which is supposed to get removed A or B? Try something like:

Code:
cd /B
for file in * ; do
     [[ -f  /A/$file ]] && rm $file
done
This is ksh code.

rm -i is interactive. You can't do that reasonably in a cron job. And your rm looks like you want to remove a file and some other whole directory. ???
  #5 (permalink)  
Old 12-20-2004
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
I modified yr script ...
  • #!/usr/bin/ksh

    for file1 in `ls $1`
    do
    grep $file1 $2
    if test $? -eq 0
    then
    echo "duplicate file $file1 found at $2 "
    else
    echo "duplicate file not found"
    fi
    done



Pass params on the command line ... and modify the script depend on yr case ...
  #6 (permalink)  
Old 12-20-2004
ghazi ghazi is offline
Registered User
  
 

Join Date: Dec 2004
Posts: 15
I have done some change and it is working for me. I going to modify it further to meet my needs.

LOG=/test/temp/DUP_CHECK.`date '+%Y%m%d%H%M%S'`

file_1=$1
file_2=$2

for file1 in `cat $1`
do
grep $file1 $2
if test $? -eq 0
then
echo "duplicate file $file1 found at $2 " >> $LOG 2>&1
else
echo "duplicate file not found" >> $LOG 2>&1
fi
done


Thanks for your help.
Ghazi


I appreciate your help.
Sponsored Links
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:12 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