Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <regex.h>
- int main(int argc, char *argv[]){
- int n1,n2,rc;
- FILE *fp;
- char buff[1000];
- regex_t preg;
- regmatch_t mat;
- n1=0;
- n2=0;
- regcomp(&preg, "^.{11}\\s\\d\\d:\\d\\d:\\d\\d\\s\\S+\\s\\w+\\.\\w+\\s\\w+:\\s+ACCEPT|REJECT|DROP\\s+.*$", REG_EXTENDED);
- fp=fopen("kern.log","r");
- while(fgets(buff,sizeof(buff),fp) != NULL){
- rc=regexec(&preg, buff, 1, &mat, 0);
- if(rc>0){
- n1++;
- } else {
- n2++;
- }
- }
- printf("count: %u %u\n",n1,n2);
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement