C Program to Simulate grep Command in Linux

This post contains C program to simulate grep command in Linux or Unix operating systems

Simulation of  grep command in Linux

#include<stdio.h>
#include<string.h>
main()
{



char fn[10],pat[10],temp[200];
FILE *fp;
printf("Enter file name\n");
scanf("%s",fn);
printf("Enter pattern to be searched\n");
scanf("%s",pat);
fp=fopen(fn,"r");
while(!feof(fp))
{
fgets(temp,1000,fp);
if(strstr(temp,pat))
printf("%s",temp);
}
fclose(fp);
}

No comments :

Post a Comment