Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Created May 15, 2017 20:24
Show Gist options
  • Save davidwtbuxton/b0ea7a5b1d3a316d56b5ed1224a11d5e to your computer and use it in GitHub Desktop.
Save davidwtbuxton/b0ea7a5b1d3a316d56b5ed1224a11d5e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import csv
import hashlib
import sys
# Calculate an MD5 checksum for every row in the first column of a CSV.
# Example:
# $ python digests.py < src.csv > dest.csv
def main():
reader = csv.reader(sys.stdin)
writer = csv.writer(sys.stdout)
for row in reader:
value = row[0].strip()
digest = hashlib.md5()
digest.update(value)
result = digest.hexdigest()
writer.writerow((value, result))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment