Running md5sum on a list of files

Hello,

I would like to run md5sum on a list of files saved in a text file, and save the result in another file. (ie. md5sum `cat list.txt` > md5list.txt)

I have tried several things, but I am always confronted to the same problem: some of the filenames have spaces.

I have run sed on the list to escape all the spaces, but shell still considers them as parameter separators.

How would you do that ?

Thanks !

I was reading other posts while waiting for a reply, and found the solution in one of them: xargs.

The right command is:

xargs md5sum < list.txt >md5list.txt

...even that will break for filenames with spaces, use a while loop instead, a bit slower but safer...

while IFS= read line 
 do 
    md5sum "$line" 
 done < list.txt > md5list.txt

Don't forget "quoting".

True, it breaks if you have spaces.

The quoting also breaks if you have double quotes in your filenames, which was also my case, that's why all special chars were escaped in my list.txt file.

By the way, it might be useful to someone to know how to do that, cause it took me quite a long time to find out:

find here -type f | sed "s:[\ \',\"]:\\\&:g" > list.txt

If your filenames include other special chars, you can add them in the left part of the sed expression.

Actually I wasn't thinking of all the unhealthy characters in the filenames, your post mentioned space, the most common unwanted character, so I advised accordingly. Think of filenames with newlines embedded in them, dealing with them will be a different chapter.
I'd strongly recommend to rename those bad filenames asap, to avoid future troubles.

Yeah, you're right, spaces are the most annoying, but I also had a few others that would mess with quoting...

I'd be happy to rename all those messy files, but sometimes you just can't prevent people doing what their OS allows them to do... =\