[英]How to get the no of matched occurrences using grep command in linux?
如果我們使用grep -c選項,則每行只會給您每次出現一次。 但是我需要匹配的事件總數而不是行數。
您可以使用-o
標志僅輸出匹配的部分,然后將其通過管道傳輸到wc -w
以獲取字數。
例如: ls ~ | grep -o pattern | wc -w
ls ~ | grep -o pattern | wc -w
使用此grep -o模式路徑| wc -l
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.