Operating System - HP-UX
1846596 Members
2355 Online
110256 Solutions
New Discussion

Re: Compare Two Text Files Using Diff

 
morganelan
Trusted Contributor

Compare Two Text Files Using Diff

Hi, any one can help me, I have one problem:

I have 2 directories: /diff and /diff1

In both of those directories, there are many files that have the same name :
file1,file2,file3 .......,filen....
How to create a log file that describe the difference between the two text files and have the following format:

File_Name Difference file created date
file1 /diff/file1:blabla.... dd-mm-yyyy
/diff/diff1/file1:blabla... dd-mm-yyyy
file2 /diff/file2:blabla.... dd-mm-yyyy
/diff/diff1/file2:blabla... dd-mm-yyyy
..... .......... .........

filen /diff/filen:blabla.... dd-mm-yyyy
/diff/diff1/filen:blabla... dd-mm-yyyy

Thank you in advance.
Kamal Mirdad
3 REPLIES 3
Yogeeraj_1
Honored Contributor

Re: Compare Two Text Files Using Diff

hi,

try: dircmp -d dir1 dir2

dircmp examines dir1 and dir2 and generates various tabulated information about the contents of the directories. Sorted listings of files that are unique to each directory are generated for all the options. If no option is entered, a sorted list is output indicating whether the filenames common to both directories have the same contents.

hth
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Christian Gebhardt
Honored Contributor

Re: Compare Two Text Files Using Diff

Try this

#!/bin/sh

cd

for file in `ls diff`
do
ls -l diff/$file | awk '{printf("%s %s-%s-%s\n",$9,$7,$6,$8)}'
ls -l diff1/$file | awk '{printf("%s %s-%s-%s\n",$9,$7,$6,$8)}'
echo "diff/$file | diff1/$file"
sdiff diff/$file diff1/$file
echo
done


Chris
john korterman
Honored Contributor

Re: Compare Two Text Files Using Diff

Hi,
try the attached script as a starting point. DIR1 and DIR2 must be configured to point at the two dirs you want to compare.

regards,
John K.
it would be nice if you always got a second chance