So many ways to do it, although it should be noted that this may be undesirable - normally you verify a pre-computed md5 hash by looking at a file that contains both the md5 hash and the file name (exactly the format that the md5sum application puts it out in). You might want to look at Wikipedia's article on md5sum for information on how it is normally used.
As for what you are apparently trying to do -
We know that the standard output of md5sum is going to be a 32 character hexadecimal string. Therefore we can cut the first 32 characters to grab just the hash:
Since we know that the first non-hash character is a space, we can set that to be our delimiter, and then grab the first field:
Alternatively, we know that the hash will be the first word in the output, so we can just print the first word:
We could use the split command to break it into multiple files, based on the byte size:
I'm not sure what any of this has to do with the Korn Shell.
Just in case anyone's interested, however, I'll note that the md5sum program can not only run a sum on a single file - it can do a whole collection of files from a single command, with the sum and filename on each line. In fact, that's the reason WHY the filename is included on the output line. This is a feature that's popular with those who setup tamper-resistant websites as well as for people who want to detect possible intrusion or corruption of critical files on their local machine.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Jan 14, 2002
Thanks for helps, but something strange is that i find the md5sum command in different linux generate different result, for example, i have tried the same file in CentOS and Rhel, The md5 results are different, it is quite headache, who know the tricks?
Are you sure it is the exact same file? And not just a similar file but released for that distro? If you copied the file (as binary!) from one machine to another, the md5sum should always be the same, regardless of the oS on the machines.
I'll turn your statement the other way around Peter.
Since calculating the MD5 hash on a file uses a very specific algorithm that must be the same on all machines, the fact that the resultant hash is different on different operating machines means only one thing - the files are guaranteed to be different.
I'll put one little caveat on this - the MD5 algorithm is very well known, so many people use it within their own software for such things as password encryption. However there are security risks if the same password in different applications created the same hash. Most applications therefore allow for different seeds on an installation basis, which results in different hashes for the same input not only on an application by application basis, but also on an installation by installation basis.
However this caveat is irrelevant for calculating the MD5 hash for a physical file - the seed is guaranteed to be the same on all operating systems, as is the algorithm, so therefore if the files are the same then the hash will be the same.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com