I'm trying to output to a text file a md5 checksum of each file in a folder in this specific format:
checksumhash1 *NameOfFile1.ext
checksumhash2 *NameOfFile2.ext
checksumhash3 *NameOfFile3.ext
etc...
Here's an example of the output would need to be:
00c0eb18b7bfd2bf985451ae3ad5d68e *My Text File.txt
4935705ea05dabef98921b18aeeaadd3 *Another file.wmv
Tried the command below, and that is as close as I can get:
md5 -r * | tee checksum.txt
From there I'm lost and can't figure out how to make the output of md5 match the formatting I need. I just need that "*" in front of the file name.
Any Gurus out there? =P
Answer
You can chain the output you're already getting into sed
(or another stream editing programme) to add in the extra character needed:
$ md5 -r * | sed 's/ / */'
69c3da625b4570f94889c9562453d394 *file1.ext
8046313ae98a6c9f1cb2c9957cdfbe7c *file2.ext
16250bebbd00e759138d09dd0cab0cb8 *file3.ext
d41d8cd98f00b204e9800998ecf8427e *file with space.ext
In this case, the sed
command just replaces the first [space] with [space][asterisk]. You can modify the expression as required if you need it to behave differently.
No comments:
Post a Comment