简体   繁体   中英

Linux command to count number of occurrences of a string in a specific file type within the whole dir

i used the following cmd to count lines of class appears within h extension files

grep -rc 'class' --include \*.h mydirc|wc -l

however, i think the result is wrong when i add up the number of occurrence for each file, it's wrong. I found the wc -l was actually counting the number of files that was searched and printed on the screen. For exmaple,

/afs/eos/dist/ds5-2013.06/FastModelsTools_8.2/OSCI/Syst...sc_buffer.h:6

i added the number of h: up, it didn't match the final value. The final value actually matches the number of printed lines on the sreen which is the same as the number of .h extension files it has searched.

怎么样

find . -name \*.h | xargs grep class | 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM