If we use grep -c option it will give you the each occurrences only once per line. But I need the total no of matched occurrences not line count.
You can use -o
flag to output only the matched part and then pipe it to wc -w
to get word count.
Eg: ls ~ | grep -o pattern | wc -w
ls ~ | grep -o pattern | wc -w
Use this grep -o pattern path | wc -l
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.