Home > utility > grep.m

grep

PURPOSE ^

SYNOPSIS ^

function output=grep(filename, pattern)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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);

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003