簡體   English   中英

檢查目錄中的任何文件是否包含常量文件中的單詞

[英]Check if any file in a directory contains words in a constant file

我有一個包含 n 個文本文件的目錄。 現在,我想檢查這些文件中是否有一個包含一個(或多個)常量文件的單詞。 這些文件都是字數不同的字典。 常量文件是一個密碼列表,我想在其中檢查這些單詞。 正確命中的數量應該保存在一個變量中。 這個詞也應該保存在一個變量中(我認為是一個數組)。

例如: file1包含This is my dictionaryfile2包含And another one ,我的密碼列表包含this is a test for the dictionary and we have no other one 從匹配file1This is dictionaryn1=3個字),並從file2 and onen2=2個字)。

我現在的代碼是

#!/bin/bash
# program_call passwordlist.txt *.txt
passwordlist="$1"
dictionarys="$*"
for comparison in  $dictionarys; do
  cat $passwordlist $comparison| sort | uniq -d >${comparison}.compare
done

我最大的問題之一是,我有不同數量的字典。 也許是 2,也許是 200。沒關系,所有這些都必須根據密碼列表進行檢查,結果(正確的單詞和正確的單詞本身)必須保存在他的 OWN 變量中。 所以我認為每個字典有兩個變量。

其它的辦法

$ for f in file{1,2}; 
  do echo -n $f": "; 
     grep -iow -f <(tr ' ' '\n' <cons) $f | 
     wc -l; 
  done

file1: 3
file2: 2

將常量文件每行轉換一個單詞,檢查字典文件中的單詞匹配忽略大小寫並計算匹配的出現次數。

我的解決方案:

#!/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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM