cancel
Showing results for 
Search instead for 
Did you mean: 

Help in script

 
SOLVED
Go to solution
Highlighted
Frequent Advisor

Help in script


Hi ,

I need to compare ~ 200 files in 2 diffrent directories using cksum command . and get the diffrence files ....

10x
4 REPLIES 4
Highlighted
Honored Contributor
Solution

Re: Help in script

Basic approach:

1.) create names for two temporary files

TMPFILE1=$(mktemp)
TMPFILE2=$(mktemp)

# make sure they will be auto-removed when the script terminates, even if there is an error
trap "rm -f $TMPFILE1 $TMPFILE2 2>/dev/null" EXIT

2.) run cksum on the files of the first directory, store the output to the first temporary file

3.) run cksum on the files of the second directory, store the output to the second temporary file

4.) run "diff" on the both temporary files to pick out the differences.


Questions:
Do you need to compare *all* the files in those directories? Or just a subset of ~200 files while the directories may have more than that?

If the latter, how can you get the list of filenames to compare? (Command line/wildcard expression, environment variable, file containing a list of filenames, something else?)

MK
MK
Highlighted
Acclaimed Contributor

Re: Help in script

>MK: 4) run "diff" on the both temporary files to pick out the differences.

You may want to run comm(1) instead of diff.
You will have to put the names before the checksums:
cksum * | awk '{print $3, $1, $2}' > $TMPFILE1

Then: comm -3 $TMPFILE1 $TMPFILE2

Of course you could do a directory diff if both directories are available on the same machine.
Highlighted
Honored Contributor

Re: Help in script

> [...] using cksum command [...]

Why? Have you considered "diff -q"?

> [...] and get the diffrence files ....

Do you mean a list of the names of the files
which differ, or a list of the differences?

What, exactly, would you like to see?
Highlighted
Frequent Advisor

Re: Help in script

thanks all.