Tuesday, March 1, 2011

String Processing Using Shell --- egrep + cut + awk

[1] Dreams soft




USING EGREP AND AWK SHELL
------------------------------






USING EGREP AND CUT SHELL
-------------------------------




CALLING STRING PROCESSING SHELL FROM C PROGRAM
-------------------------------------------------
int main()
{
#define MAXLINE 100

FILE *fpin;
char line[MAXLINE];
char line1[MAXLINE];
bool lbFound;

strcpy(line,"cat networkshow.txt|egrep '1: |2: |3: '|cut -d \":\" -f2");
printf(line);
printf("\n");

if ((fpin = popen(line,"r")) == NULL )
err_says("popen error");

lbFound=false;

while(fgets(line1,MAXLINE,fpin) != NULL){
if(strcmp(line1," ppp0\n")==0){
printf("Found ppp0\n");
lbFound=true;
break;
}
printf(line1);
}

if(lbFound==false)
printf("No ppp0 found.\n");

return 0;
}

No comments: