1

I feel this question has been asked before but I am having trouble locating an answer and it combinations of possibilities is mind boggling. Many resources provide something almost close but I'm having trouble getting the expressions in grep correct for my issue.

I am creating a wordlist using crunch with alphanumeric output:

crunch 8 8 ABCDEFGHIJKLMNOPQRSTUVWXYZ + 1234567890 -t %@%@%@%@

This will output 8 alphanumeric strings with an alpha and a number like so:

1A1A1A1A1A
1A1A21B2A3
1A1A31A1A3
...

I have been trying to pipe the output to grep where the final result will omit output with any character in any pattern repeats. Due to the nature of the crunch output, consecutive repeats are already eliminated. Is there a correct expression to omit the non consecutive ones? Or is there a possible way to do this with just crunch?

1A1A1A1A1A not output
1A1A21B2A3 not output
1A1A31A1A3 not output

acceptable output:

1A2B3C4D
1B2A3D4C
1C3A2F5G

Any help with trying to understand the expressions in this regard is greatly appreciated.

2

With back-references:

grep -v '\(.\).*\1'

-v is to reverse (print the lines that don't match), and the regexp is \(.\) any single character captured, followed by any number of characters (.*) followed by the same character \1 captured earlier.

1
  • Ah! I've been trying to set up grep with -E rather than -v. This is working. Many thanks for your help! – Remembermyname Jan 3 '20 at 22:18

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.