Last active
March 17, 2024 01:30
-
-
Save rindeal/21218d51c2c52b157e2089e4c3ad6b71 to your computer and use it in GitHub Desktop.
Generate multiple hashes for a file and print them as a markdown table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# requires `pee` command from `moreutils` suite | |
SUMS=( | |
md5sum | |
sha1sum | |
sha256sum | |
) | |
FILE="${1}" | |
printf '<details>\n' | |
printf '<summary>Checksums for <code>%s</code>:</summary>\n\n' "${FILE}" | |
pee "${SUMS[@]}" < "${FILE}" | \ | |
awk ' | |
BEGIN { | |
'"$( | |
for i in $(seq 1 ${#SUMS[@]}) | |
do | |
printf 'a[%d]=\"%s\"\n' $i "${SUMS[$((i - 1))]}" | |
done | |
)"' | |
print "Name | Value" | |
print "-------------- | -----------------------" | |
} | |
a[NR] { | |
printf "%-14s | %s\n", "**"a[NR]"**", $1 | |
} | |
' | |
printf '\n</details>\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment