md5sum file.png | awk '{print $1}' | wc -m
I get: 33
I expect it will return 32
as the length of md5 hash. After read man page and googling I still didn't find out why.
TL;DR
Use awk's length()
function:
md5sum file.png | awk '{print length($1)}'
32
It's because awk
will add a line feed character to the output. You can check:
md5sum file.png | awk '{print $1}' | xxd
You can tell awk to not doing that using ORS
output record separator variable:
md5sum file.png | awk '{print $1}' ORS='' | wc -m
32