2015-05-27 26 views
1

我目前使用近似grep(Agrep)來獲得數千個短字符串列表與數百萬個更長字符串列表之間的匹配。如何更快更換agrep?

任務:

找到 'ABCDE', '... ... XYZABCDEFG' 甚至 'ABCD' '... ... XYZqBCDEFG'(1個錯)

AGREP工作正常,但對於我必須做的事情來說太慢了(字符串匹配與1不匹配)。任何人都可以推薦更快的選擇嗎?

+1

您需要更清楚地瞭解您「必須做」的內容。 –

+0

更新了示例 – Monoandale

回答

3

我不知道這個答案的表現將如何與你現在擁有的相比。

開始與

one_mismatch_regex() { 
    local patterns 
    for ((i=0; i < ${#1}; i++)); do 
     patterns+=("${1:0:i}.${1:i+1}") 
    done 
    local IFS='|' 
    echo "${patterns[*]}" 
} 

做這個:

$ one_mismatch_regex foobar 
.oobar|f.obar|fo.bar|foo.ar|foob.r|fooba. 

所以:

while read search_word; do 
    one_mismatch_regex "$search_word" 
done < searches.txt | 
grep -E -f - data.txt 

while循環將改變搜索詞的列表爲正則表達式,將匹配單詞有一個不匹配,並寫入正則表達式到標準輸出。然後,grep將使用擴展正則表達式匹配(-E)並從名爲-(stdin)的文件中讀取正則表達式。

+0

感謝您的幫助。它看起來像服用同一時間: 17:08:58.450521007 +0100 end_regex.txt 17:08:20.494522421 +0100 start_regex.txt 17:07:14.418524883 +0100 end_agrep.txt 17:06:39.930526168 +0100 start_agrep.txt agrep 35秒,正則表達式38 – Monoandale