0

I have a file with about 7 million passwords with mixed Lower Upper digits

all have the same length 8 symbols

I want to remove the passwords than contain 5 or more digits not necessary consecutive:

Example:

A0s123tf - OK
tttttttt - OK
096545aZ - Remove
Z0123456 - Remove
z445Jz55 - Remove -> fail

if I do for example:

grep -E -v '[0-9]{5,} myfile 

fail with the last word because the numbers aren't consecutive.

What is the correct regex for this case?

3
  • so.. /(.*[0-9].*){5}/?
    – DopeGhoti
    Jan 4 '19 at 20:09
  • grep -E -v '(.*[0-9]){5}' file or grep -E -v '([0-9].*){5}' file should be enough.
    – jimmij
    Jan 4 '19 at 20:11
  • 1
    On a tangential note, someone has done some very bad things if these are actual passwords. They are not hashed, they are shorter than the absolute minimum which should be required these days, and they have a counter-productive format restriction (all of these points have been discussed at great length elsewhere). If this is related to a production system you're working on, you'd better get someone familiar with proper password handling in ASAP. Someone is at least morally, and possibly criminally, negligent.
    – l0b0
    Jan 4 '19 at 20:40
1

Do you need it to be a regexp, or can you pipe? A hacky way to do it would be to look for 5 digits

$ cat j
A0s123tf
tttttttt
096545aZ
Z0123456
z445Jz55
$ grep -E -v '\d.*\d.*\d.*\d.*\d' j
A0s123tf
tttttttt
$
1

Alternatively, search for the inverse; since they're each eight characters long, require 4 non-digits:

grep -E '[^[:digit:]].*[^[:digit:]].*[^[:digit:]].*[^[:digit:]]' myfile

or condensed a bit:

grep -E '([^[:digit:]].*){4}' myfile
1
  • Running some timing tests on 7 million randomly generated 8-char passwords, I'm getting around 7.7 sec for the 4 * not-a-digit search, and around 6.5 sec for 5 * is-a-digit search. Couldn't tell you why, though.
    – mmusante
    Jan 4 '19 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.