1

I've been trying to solve this all day and I am lost at this error as it doesn't make sense. I have two files; hashed.txt and dehashed.txt.

The hashed.txt file contains the following items:

00000000a8dae4228f821fb418f59826079bf368:2                   
00000000dd7f2a1c68a35673713783ca390c9e93:630                 
00000001e225b908bac31c56db04d892e47536e0:5                   
00000006bab7fc3113aa73de3589630fc08218e7:1                   
00000008cd1806eb7b9b46a8f87690b2ac16f617:3                   
0000000a0e3b9f25ff41de4b5ac238c2d545c7a8:14                  
0000000a1d4b746faa3fd526ff6d5bc8052fdb38:16                  
0000000caef405439d57847a8657218c618160b2:15                  
0000000fc1c08e6454bed24f463ea2129e254d43:40   

The dehashed.txt file contains the following items:

00000000a8dae4228f821fb418f59826079bf368:1397wpfk
00000000dd7f2a1c68a35673713783ca390c9e93:89378305686
00000001e225b908bac31c56db04d892e47536e0:64769480a
00000006bab7fc3113aa73de3589630fc08218e7:6597812222
00000008cd1806eb7b9b46a8f87690b2ac16f617:553193251
0000000a0e3b9f25ff41de4b5ac238c2d545c7a8:6004468405
0000000a1d4b746faa3fd526ff6d5bc8052fdb38:+79250455754
0000000caef405439d57847a8657218c618160b2:k65jlnzrvtu9
0000000fc1c08e6454bed24f463ea2129e254d43:291vnnzrvtu9

The bash script that I wrote is very simple as it should merge the two lists into one by the vlookup of the hash, like so:

2:00000000a8dae4228f821fb418f59826079bf368:1397wpfk
630:00000000dd7f2a1c68a35673713783ca390c9e93:89378305686
5:00000001e225b908bac31c56db04d892e47536e0:64769480a
1:00000006bab7fc3113aa73de3589630fc08218e7:6597812222
3:00000008cd1806eb7b9b46a8f87690b2ac16f617:553193251
14:0000000a0e3b9f25ff41de4b5ac238c2d545c7a8:6004468405
16:0000000a1d4b746faa3fd526ff6d5bc8052fdb38:+79250455754
15:0000000caef405439d57847a8657218c618160b2:k65jlnzrvtu9
40:0000000fc1c08e6454bed24f463ea2129e254d43:291vnnzrvtu9

Here is the script that I wrote:

#!/bin/bash
IFS=:
while read -r hash decrypted; do
        line=$(grep --max-count 1 "${hash}" hashed.txt)
        count=$(echo "${line}" | cut -f2 -d:)
        echo "${count}:${hash}:${decrypted}"
done < dehashed.txt

However, it doesn't print the count variable.

:00000000a8dae4228f821fb418f59826079bf368:1397wpfk
:00000000dd7f2a1c68a35673713783ca390c9e93:89378305686
:00000001e225b908bac31c56db04d892e47536e0:64769480a
:00000006bab7fc3113aa73de3589630fc08218e7:6597812222
:00000008cd1806eb7b9b46a8f87690b2ac16f617:553193251
:0000000a0e3b9f25ff41de4b5ac238c2d545c7a8:6004468405
:0000000a1d4b746faa3fd526ff6d5bc8052fdb38:+79250455754
:0000000caef405439d57847a8657218c618160b2:k65jlnzrvtu9
:0000000fc1c08e6454bed24f463ea2129e254d43:291vnnzrvtu9

if I print just echo "${count}", it works fine, but when I add a semicolon or a comma after it, it stops working. I also tried printf but I got the a different error. If I use printf '%d:%s:%s\n' "$count" "${hash}" "${decrypted}", it prints fine but then I also get this error:

invalid numberline 10: printf: 1

If anyone can help me with this, it will be greatly appreciated. Also, these two files are about 30GB each so any solutions would have to work with that.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Raza
  • 3,147
  • 2
  • 31
  • 35
  • 1
    Are you sure about the output it gives? On my machine you code produces correct output. (Just adds some extra whitespaces which i removed by piping thtough `tr -d ‘ ‘`) – Mihir Luthra Aug 03 '19 at 08:47
  • Yeah, I just tested it out https://imgur.com/eJxWaAQ. – Raza Aug 03 '19 at 09:17
  • 3
    Your files are in DOS format (trailing Carriage Return at the end of each line). There's probably a duplicate question somewhere. Try `line="${line%$'\r'}"` to strip the CR. – melpomene Aug 03 '19 at 09:23
  • Yes, That was the issue. Thank you very much. I didn't even know to debug this issue. – Raza Aug 03 '19 at 09:32

0 Answers0