Home > Blockchain >  Hash each line of a Textfile with md5, write it to another File
Hash each line of a Textfile with md5, write it to another File

Time:05-13

How can i write each line of that source.csv in a file. Source look`s like this:

[email protected]
[email protected]
[email protected]

I want to have this in a file - but only the md5 of every string in line from above.

hashed.csv should look like that, in the end - after opening.

2d8c986e36035c262131c06e1579b430
da5a21d0bc55368a719957918d4b3992
2de6b5d122434085d83ff45e8131bba6

CodePudding user response:

You could do this:

#!/bin/bash

>hashed.csv

while IFS= read -r line; do
    printf "%s" "$line" | md5sum | awk '{print $1}' >>hashed.csv
done < source.csv
  • printf is used since echo would add a \n after the line.
  • awk is used to remove the - that md5sum adds after each checksum.

CodePudding user response:

Maybe there is no sort in it.

Firstline in Source must be firstline in hashed.

maybe at the end the file look like this:

[email protected];2d8c986e36035c262131c06e1579b430
[email protected];da5a21d0bc55368a719957918d4b3992

i paste the md5 hashes to Email, after that. But maybe we can do it in one run.

thanks

  •  Tags:  
  • bash
  • Related