I need to compare two file contents and log the difference. the detail as below:
in current directory there is file
abc20140728_1020.txt
abc20140728_1110.txt
I need to find the files which created within 60 minutes first then compare the contents.
I am able to use find command find the files but I don't know how to compare these two file contents.
for filename in `find srch_dir -cmin -60 -name abc2014*`
do
here i don't know how to store the first file then use diff $filename1 $filename2
done
Hi Don Cragun
for my script, after finding the files, I need to output to tmp file then do something, then compare.
for below code, how can I put them in while loop.
find srch_dir -newer "$IAm.$$" -name 'abc2014*' | (
read file1
while read file2
do diff "$file1" "$file2"
done
)
when first time running the script there is no any files in the directory. the find command only find one file, I don't need to compare. what i want to do is after finding the file(s), first I want to count how many files I found, if it is one, I don't compare; if it is two files, I will compare.
Why do you want to count the files. The script I gave you won't do anything unless there are at least two files. If there are two or more files, it will execute the commands in the while loop once for each file except the 1st file. The name of the 1st file is preserved in the variable file1 and doesn't change while the name of each remaining file is stored in the variable file2 as it is processed in the loop.
You have said you want to create a temp file, but you haven't shown us what would go into that temp for nor what it would be used for. Then you said you want to do something else, but you haven't said what. Then, if there are two or more files, you said you want to compare the files; the script I gave you does that.
Did you try running the script I gave you when 0, 1, 2, and 3 files with names starting with abc2014 were present that had been created within the last hour? For each case, what did the script do wrong?