Operating System - HP-UX
1753773 Members
5548 Online
108799 Solutions
New Discussion юеВ

Re: File comparions - Directory levels

 
reddykumar
Occasional Contributor

File comparions - Directory levels

prd path # Production files
tst path # tst files

Note:

This is a delimater "|" dat file.


These directories are having many files , and these file names and layouts are same in production to testing.

I need to check if the prd directory files and tst directories files are same or not( line by line check) . If same then i should get message saying that : Files are matching and also with file names : sizes"

If not matching..those files needs to redirected to the other directory : with the diff report of the lines not matching.

KIndly please help me desinging the script in unix/shell/perl

Thanks for your time!








4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: File comparions - Directory levels

Hi:

Have a llok at 'diff' and 'dircmp'. See their manpages for more information.

Regards!

...JRF...

reddykumar
Occasional Contributor

Re: File comparions - Directory levels

Hi

I just had try with this,, but not working. PLease can you modify this code to work correctly

prd=/ahome/prkkl/test
tst=/ahome/prkkl/test1
diff=/ahome/prkkl

cd $prd
for a in `ls`; do

if [ ! -f "../$tst/$a" ]; then
continue
fi
diff $a ../$tst/$a > /dev/null
if [[ "$?" == "1" ]]; then
cp $a ../$diff
else
echo "Files are matching"
fi
done
James R. Ferguson
Acclaimed Contributor

Re: File comparions - Directory levels

Hi:

First, what is "not working" for you.

( By the way, you use 'diff' as the variable name whereas it is the name of a command. This is poor form. )

Second, did you try simply using diff() to compare two directories? Consider this test case:

# ls dir1
f1

# ls dir2
f1 f2

# cat ./dir1/f1
reddykumar

# cat ./dir2/f1
ReDdYkUmAr

...Now:

# diff dir1 dir2
diff dir1/f1 dir2/f1
1c1
< reddykumar
---
> ReDdYkUmAr
Only in dir2: f2


...or if all you want is a message based on the the return code:

# diff dir1 dir2 > /dev/null && echo "SAME" || echo "DIFFERENT"
DIFFERENT

Regards!

...JRF...





Tor-Arne Nostdal
Trusted Contributor

Re: File comparions - Directory levels

#!/bin/sh
prd=/ahome/prkkl/test
tst=/ahome/prkkl/test1

cd $prd
for file in *
do
if [ ! -f $tst/$file ];then
echo "Missing file copied: $file"
cp -p $file $tst/
fi
done
I'm trying to become President of the state I'm in...