I'm working on a project for my university, requiring to go though decently large files (>50MB), and i used flex to basically rewrite a file composed of line such as
1 1:41 3:54 7:40 13:8
2 4:7 7:8 23:85
1 1 3 7 13
2 4 7 23
number_a:number_b
number_a
f
%{
#include<stdio.h>
unsigned int nb_doc = 1;//prend en compte le premier doc
unsigned int i;
%}
couple_entiers [0-9]+:[0-9]+
retour_chariot \n[0-9]+
autre .
%%
{couple_entiers} {i=0;
while(yytext[i] != ':'){
printf("%c",yytext[i]);
i++;
}
}
{retour_chariot} {nb_doc ++; printf("%s",yytext);}
{autre} {printf("%s",yytext);}
%%
int main (void){
yylex();
printf("\n\n%d",nb_doc);
return 0;
}
Consider replacing your custom code with a general solution:
system("sed -E 's/:\d+ / /g'");
:)