function [pattLine wcl] = kgrep(fname,pattern,varargin)
%usage lineNumber = kgrep(fname,pattern)
%finds the first instance of pattern 'pattern' in file 'fname'
%and returns you the associated line number;
%fname='/home/oper/vis_guiD/vis_gui/data/feb14/EDSTONL51.avg'

uxcmd=['''wc -l ',fname,''''];
cmd=['[s w]=unix(',uxcmd,');'];
eval(cmd);
s;
wc=w(1:length(w)-length(fname)-1);
wcl=str2num(wc);
pattLine=[];
fid=fopen(fname,'r');
ctr=1;
while ctr<wcl
L=fgetl(fid);
%S = regexp(L,'%%')
%if strcmp(varargin{1},'all')
S = regexp(L,pattern);
if length(S)~=0
    pattLine=[pattLine ctr];
    
    %break
end;
ctr=ctr+1;
end;

fclose(fid);