11

I need to get the md5 sum of a file on AIX, but the md5sum program prints the sum followed by the name of the file.

How can I get the sum without the file name.

C. Ross
  • 6,734

5 Answers5

13
md5sum filename | awk '{print $1}'

That would be one way.

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
5
md5sum < filename

This will give you an empty filename.

heavyd
  • 65,321
5

Also:

md5sum filename | cut -c -32

Which has the benefit of having no quotes or characters needing to be escaped, in case you need to embed that command someplace which might have multiple string interpreters acting on it.

Ross Rogers
  • 4,807
3

Another way is to do :

md5sum filename |cut -f 1 -d " "

Cut will split line to each space and return only first field.

1

A very simple way is to assign the output to an array as explained here:

md5=( $(md5sum "filename") )
echo $md5

Another way is to strip the space and anything after it:

md5=$(md5sum "filename")
echo ${md5/ *}
mivk
  • 4,015