標題說明了一切,我需要過濾一個具有規格的egrep文件,但我無法弄清楚的是確保它發生3次。 (從問題的直接措辭 - 包含5個或更多字符的話,這至少發生三次行)UNIX - 使用egrep,如何過濾發生n次的模式?
-1
A
回答
0
隨着awk(未測試):
awk '
/\b[a-zA-Z]{5}\b/{
matches[$0]++
}
END{
for (m in matches) {
if (matches[m] >= 3) {print m}
}
}
' file
1
0
$ cat ip.txt
abc abc abc should not match
totally this line should totally match, isn't it? totally
Title: word with 5 letters like title should also match, given title is present 3 or more times
this line should not totally match, total only partly matches with totally
,以配合匹配情況下的話:無論情況
$ grep -wE '([a-zA-Z]{5,}).*\1.*\1' ip.txt
totally this line should totally match, isn't it? totally
要匹配的話:
$ grep -iwE '([a-zA-Z]{5,}).*\1.*\1' ip.txt
totally this line should totally match, isn't it? totally
Title: word with 5 letters like title should also match, given title is present 3 or more times
匹配任意五個或更多字母的序列:
$ grep -iE '([a-zA-Z]{5,}).*\1.*\1' ip.txt
totally this line should totally match, isn't it? totally
Title: word with 5 letters like title should also match, given title is present 3 or more times
this line should not totally match, total only partly matches with totally
-E
擴展正則表達式-w
匹配全字-i
忽略大小寫[a-zA-Z]{5,}
小寫或大寫字母,五次或更多次()
捕獲組和\1
被回去參考它
和一點樂趣,如果你有pcre
正則表達式
$ echo 'totally title match' | grep -P '([a-zA-Z]{5,}).*(?1).*(?1)'
totally title match
(?1)
指的是正則表達式模式([a-zA-Z]{5,})
本身
相關問題
- 1. 使用egrep的Unix搜索模式
- 2. Unix egrep命令如何創建一個匹配以下模式?
- 3. 如何通過n過濾文件。模式後的字符串?
- 4. 如何使用string.find找到最後一次發生的模式?
- 5. Linux:使用egrep計數發生
- 6. 如何使用意圖過濾器來過濾文本模式
- 7. 如何使用egrep正則表達式?
- 8. 正則表達式,匹配不超過n次發生
- 9. 在一次傳遞中生成多個過濾器的模式
- 10. WHERE過濾何時發生?
- 11. UNIX egrep多個字符串
- 12. grep在linux模式(重複/發生超過n)
- 13. 如何過濾unix中的列
- 14. 使用模式的過濾器陣列
- 15. 如何使用AWK過濾用戶CN的矩陣模式?
- 16. Python中模式的多次發生
- 17. 使用egrep的
- 18. 如何使用Ruby製作標準的Unix過濾器?
- 19. JavaScript正則表達式替換如果發生多次n
- 20. 如何使用1d過濾器生成2d過濾器
- 21. 使用變量替換每次發生的模式
- 22. 如何使用jQuery模板生成N X N表格
- 23. 如何用n-arg謂詞過濾n元組的seq?
- 24. HLOOKUP/INDEX中的第N次發生
- 25. 如何使用基於模式的RxJS observables過濾數據
- 26. 使用bash編寫Unix過濾器
- 27. 有n次運行,x是在n次運行中發生事件的最少一次發生的概率
- 28. 刪除接下來的N次發生使用單線程
- 29. 事件發生n次的最佳方式?
- 30. django模式如何被位過濾
感謝提供樣品輸入/輸出 –
您是否嘗試過的東西? –
我無法弄清楚如何在運行grep時檢查它是否符合發生次數。到目前爲止,我有\\ egrep'\ b [a-zA-Z] {5} \ b'。* 其中涵蓋了我需要的所有內容,但我需要能夠將它過濾爲至少出現3次的單詞 – KenP