i have a directory with n textfiles. Now, i want to check, if any of these files contains one (or more) words of a constant file. These files are all dictionarys with a different amount of words. The constant file is a password list, where i want to check these words. The amount of correct hits should be saved in a variable. Also the word should be save (i think as an array) in a variable.
For example: file1
contains This is my dictionary
, file2
contains And another one
, my password list contains this is a test for the dictionary and we have no other one
.
The hits from file1
are This is dictionary
(n1=3
words) and from file2
and one
(n2=2
words).
My present code is
#!/bin/bash # program_call passwordlist.txt *.txt passwordlist="$1" dictionarys="$*" for comparison in $dictionarys; do cat $passwordlist $comparison| sort | uniq -d >${comparison}.compare done
One of my biggest problems her is, that i’ve got a different amount of dictionarys. Maybe 2, maybe 200. Nevermind, all of these has to be checked against the passwordlist and the result (the amound of correct words and the correct word itselfs) has to be saved in his OWN variables. So i think two variable for each dictionary.
Advertisement
Answer
My solution:
#!/bin/bash # program_call_is /dictionarys/*.txt passwordlist.txt dictionarys="$1" shift passwordlist="$*" for comparison in $dictionarys; do fgrep -x -f $passwordlist $comparison >${comparison}.compare done