j@j:~$ cat hello.c
#include<stdio.h>
//include include
int main(){
printf("hello world/n");
exit(0);
}
j@j:~$ grep -o include hello.c
include
include
include
如上所示, 所有的include都显示出来了, 包括有两个include的行。
命令grep -c -o include hello.c的结果是2, -c参数只能统计行。如果要统计个数, 可以再来个重定向:
grep -o include hello.c | grep -c include
得到include的个数 3
#include<stdio.h>
//include include
int main(){
printf("hello world/n");
exit(0);
}
j@j:~$ grep -o include hello.c
include
include
include
如上所示, 所有的include都显示出来了, 包括有两个include的行。
命令grep -c -o include hello.c的结果是2, -c参数只能统计行。如果要统计个数, 可以再来个重定向:
grep -o include hello.c | grep -c include
得到include的个数 3
本文介绍如何利用grep命令来统计C语言源代码文件中特定关键字出现的次数。通过具体的例子展示了如何区分行计数与单词计数,并提供了一种有效的方法来统计诸如 'include' 这样的关键字在源文件中出现的频率。
551

被折叠的 条评论
为什么被折叠?



