Created
October 25, 2020 08:30
-
-
Save airglow923/96322fb2e9fa73e6bc51ab62f5ee3316 to your computer and use it in GitHub Desktop.
Convert each line to hash
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/bash | |
usage() { | |
echo "Usage: $0 -i [INPUT] -o [OUTPUT] -a [HASH_ALGORITHM]" | |
1>&2; | |
exit 1; | |
} | |
input="" | |
output="" | |
algo="" | |
OPTIND=1 | |
while getopts ":i:o:a:" opt; do | |
case "$opt" in | |
i) | |
input=${OPTARG} | |
;; | |
o) | |
output=${OPTARG} | |
;; | |
a) | |
algo=${OPTARG} | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[ "${1:-}" = "--" ] && shift | |
if [ -z "${input}" ] || [ -z "${output}" ] || [ -z "${algo}" ]; then | |
usage | |
exit 1 | |
fi | |
while read p; do | |
echo -n "$p" | "${algo}"sum | cut -d ' ' -f 1 >> "${output}" | |
done < "${input}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment