1

Absolute beginner here.

I have a list of passwords in a file named "pw.prn".

Welcome99
ABCDEFGH
12545678
lakers2021
gododgers

I wish to run each line in the file against a hashing program (mkpasswd -m sha-512) and output the password concatenated with a semi-colon then results of the hashing process to a new file:

So the output would look like this:

Welcome99:$6$xDb6xNDzqtnwzVLz$LMA3CNodueIyZavW3CIGDdcl19cekNNG8EB5Hc/vMzZGUSRhbueNCkYRlyaGKAb/VjW0cBiCHdJLt4iL08gBn/
ABCDEFGH:$6$mANzCeK.SUgSD$ID/E6NYPp4cddHCevI.yua3HotbA/a7fZ7xjSk7dUI6fayuTMsO9SCdSA7MFcgh8SUcmNqrqqE4IxAoIEcmFb0
12345678:$6$CwjNF9B1Q8bkwohy$N4eZcj6YPxxbA1MYz0k9t96nCcj9VsZmzrvgqTd9tp2yXbzAdb3hWyjBq6nquMwFbKMJw9ZXs3Uqj.gfnozUS0
lakers2021:$6$fENvTJijoQgyjWMo$W37vZ364wQugW.W7k9Gl8OfJLl8DfR3tpFO/O4oPTCazJgNkJfNE4WiP4z8qSM8H1.ZJrMUWVAYdYOxt0GSHG1
gododgers:$6$1JdXTdpguO0$ZwFoDtZZ2byDemiLv5JAuea6ucAdtYQUTC4EppX2PMzSLaYtMm/ENpBZZAy70Ceuu6yAjXYtggrSOINTRWoBi0

Unfortunately, I have no "code that I have tried" as I do not even know where to being. Is this a for loop? While? I have tried searching using bash script with interactive answers from a file but have not been able to piece anything together.
I hope that my example provides enough information to understand what I am looking for. I am running this on Ubuntu Linux Thank You

Jetchisel
  • 7,493
  • 2
  • 19
  • 18
T011AZ3
  • 11
  • 1

1 Answers1

2

You could use a while + read loop. See How can I read a file (data stream, variable) line-by-line (and/or field-by-field)

Something like.

#!/usr/bin/env bash

while IFS= read -r line; do
  printf '%s:%s\n' "$line" "$(mkpasswd -m sha-512 "$line")"
done < pw.prn

In bash script how do I reference a file as the input for an interactive prompt

Use a variable (positional parameter "$1")

#!/usr/bin/env bash

while IFS= read -r line; do
  printf '%s:%s\n' "$line" "$(mkpasswd -m sha-512 "$line")"
done < "$1"

Then

./myscript pw.prn

Assuming the name of the script is myscript and the file in question is pw.prn

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jetchisel
  • 7,493
  • 2
  • 19
  • 18