Skip to content

Instantly share code, notes, and snippets.

@airglow923
Created October 25, 2020 08:30
Show Gist options
  • Save airglow923/96322fb2e9fa73e6bc51ab62f5ee3316 to your computer and use it in GitHub Desktop.
Save airglow923/96322fb2e9fa73e6bc51ab62f5ee3316 to your computer and use it in GitHub Desktop.
Convert each line to hash
#!/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