




0001 function output=grep(filename, pattern) 0002 0003 output=[]; 0004 fid = fopen(filename, 'r'); 0005 line_number = 0; 0006 while feof(fid) == 0, 0007 line = fgetl(fid); 0008 matched = findstr(line, pattern); 0009 if ~isempty (matched) 0010 output=strcat(output, sprintf('%d: %s \n', line_number,line)); 0011 end 0012 line_number = line_number + 1; 0013 end 0014 0015 fclose(fid);