Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a directory containing files and an md5sum.txt file. I add a file new files to the directory. I would like add md5sum sums for all files that are not in md5sum.txt.

Is there a simple way to do it?

share|improve this question
1  
What kind of script are you looking for? What operating system are you using? –  innaM Nov 4 '09 at 21:35
    
you basically have to script reading in your md5sum.txt and directory listing and weed out from there. i'd probably choose perl for the task. –  quack quixote Nov 4 '09 at 21:49
    
I'm using Linux. –  user13798 Dec 2 '09 at 20:23
add comment

1 Answer

You can try this little number:

#We want the seperator to be newlines, not spaces
IFS="$(echo -e "\n\r")"
for EACHFILE in `ls -1`
do
    # If grep can't find the filename in that text file
    if ! egrep -q  " $EACHFILE$" md5sum.txt; then
    md5sum $EACHFILE
    fi
done

This assumes that the text file is like this:

964e6b94e921b5f0879b41956b787050 test.file

Which is standard output

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.