1

I have a .txt file that has a list containing a hash and a password so it looks likes this:

00608cbd5037e18593f96995a080a15c:9e:hoboken
00b108d5d2b5baceeb9853b1ad9aa9e5:1c:wVPZ

Out of this txt file I need to extract only the passwords and add them in a new text file so that I have a list that would look like this:

hoboken 
wVPZ
etc
etc
etc
etc

How to do this in bash, a scripting language or simply with a text editor?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
n00bpr00f
  • 11
  • 1
  • 4
    It seems your list has 3 informations, not two, if they're separated by `:`. [Here's a very similar question](http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash) that should help you in bash to split the lines in your text file. After that, it's up to you to save if to a new file (can use something like `echo >> /path/file`). Good luck. – Tom Dec 17 '16 at 03:14

4 Answers4

3

Given your examples, the following use of cut would achieve what you want:

cut -f3 -d':' /folder/file >> /folder/result

The code above would delete anything before (and including) the second colon : on each line, which would work on your case, given your examples. The result is stored on /folder/result.

Edit: I edited this answer to make it simpler.

Jamil Said
  • 2,033
  • 3
  • 15
  • 18
2

I suggest to use awk to get always last column from your file:

awk -F ':' '{print $NF}' file

Output:

hoboken
wVPZ
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Interesting approach, I voted you up. In truth, your answer could be wrong because we don't know if the password is always on the last column -- maybe in some lines we could have an extra final column, so the password would not be retrieved. On the other hand, my answer assumes that the strings before the password will only have a `:` as a delimiter and never on the string itself, which could also be wrong. Ah.. I love real life questions like that, with limited/inadequate information, they are challenging and make you think deeply. – Jamil Said Dec 17 '16 at 05:19
  • @JamilSaid: Yes, the question could be clarified. Perhaps the second column is a kind of [salt](https://en.wikipedia.org/wiki/Salt_%28cryptography%29). – Cyrus Dec 17 '16 at 05:27
2

With sed, to remove the string up to ::

sed 's/.*://' file
SLePort
  • 15,211
  • 3
  • 34
  • 44
1

You could also use grep:

$ grep -o [^:]*$ file
hoboken
wVPZ
  • -o print only matching part
  • [^:] anything but :
  • * all matching characters
  • $ end of record
James Brown
  • 36,089
  • 7
  • 43
  • 59
  • thank you soooo much, im learning so much on this community through people like yourself! Thank you everybody!! – n00bpr00f Dec 17 '16 at 10:55