pro job_edit2,file1,file2,st1,st2,once=once,tag=tag,notag=notag,$ ide1=ide1,ide2=ide2,add1=add1,add2=add2,make=make,$ silent0=silent0,nfirst=nfirst,max0=max0,file2_out=file2_out if(n_params() le 0) then begin print,'job_edit2,file1,file2,st1,st2' print,' write from file1 -> file2' print,' replace st1 -> st2' print,"file2='copy' -> save with same name as file1" print,'/once -> replace just the first occurrance in line' print,'tag=tag-string -> change only lines having this string' print,'notag=notag-string -> change only lines NOT having this string' print,'additionally: ide1=ide1, ide2=ide2 -> change these strings' print,'additionally: add1=add1, add2=add2 -> change these strings' print,"file2='make' and ide1,ide2 defined -> " print,"save by name of file1 where string ide1 replaced by ide2 -> " print,'HS 1.4.2003' print,'keyword file2_out returns the new filename (HS 260510)' return endif sile=0 if(keyword_set(silent0)) then sile=silent0 nmax=10 if(keyword_set(once)) then nmax=0 if(keyword_set(max0)) then nmax=max0 if(n_params() gt 2) then begin nst1=strlen(st1) nst2=strlen(st2) endif close,1 close,2 ijunk=0 if(sile lt 2) then print,'----------------------------------------------' if(sile lt 2) then print,'original file: ',file1 if(file2 ne 'copy' and file2 ne 'make') then begin if(sile lt 2) then print,'new file: ',file2 endif if(file2 eq 'copy' or file2 eq file1) then begin file2_oikea=file1 file2='junk' if(sile lt 2) then print,'copy file: ',file2_oikea ijunk=1 endif if(file2 eq 'make' and keyword_set(ide1) and keyword_set(ide2)) then begin file2_oikea=file1 str_replace,file2_oikea,ide1,ide2,max=1 file2='junk' if(sile lt 2) then print,'make file: ',file2_oikea ijunk=1 endif if(sile lt 2) then print,'----------------------------------------------' file2_out=file2 openr,1,file1 openw,2,file2 line='' n_change=0l while not eof(1) do begin readf,1,line lineori=line mui=0 if(keyword_set(nfirst)) then begin if(n_change gt nfirst) then goto,endi endif ;ide1 and ide2 given? mui1=0 if(keyword_set(ide1) and keyword_set(ide2)) then begin nide1=strlen(ide1) nide2=strlen(ide2) nline=strlen(line) res=strpos(line,ide1,mui1) if res eq -1 then goto,end_ide mui1=1 line1='' line2='' if(res ne 0) then line1=strmid(line,0,res) if(res+nide1 ne nline) then $ line2=strmid(line,res+nide1,nline-res-nide1) line=line1+ide2+line2 ;addition: ide appears twice in time-line (log, tlog) res=strpos(line,'/usr/bin/time',0) if(res ne -1) then begin rese=strpos(line,'exe',0) nline=strlen(line) line1=strmid(line,0,rese) line2=strmid(line,rese,nline-rese-1) str_replace,line2,ide1,ide2,max=1 line=line1+line2 endif endif end_ide: ;add1 and add2 given? mui2=0 if(keyword_set(add1) and keyword_set(add2)) then begin nadd1=strlen(add1) nadd2=strlen(add2) nline=strlen(line) res=strpos(line,add1,mui2) if res eq -1 then goto,end_add mui2=1 line1='' line2='' if(res ne 0) then line1=strmid(line,0,res) if(res+nadd1 ne nline) then $ line2=strmid(line,res+nadd1,nline-res-nadd1) line=line1+add2+line2 endif end_add: ;tag? if(keyword_set(tag)) then begin tagres=strpos(line,tag,0) if tagres eq -1 then goto,newline endif ;notag? if(keyword_set(notag)) then begin tagres=strpos(line,notag,0) if tagres ne -1 then goto,newline endif ;replace st1 by st2? if(n_params() gt 2) then begin for i=0,nmax do begin nline=strlen(line) res=strpos(line,st1,mui) if res eq -1 then goto,newline mui=1 line1='' line2='' if(res ne 0) then line1=strmid(line,0,res) if(res+nst1 ne nline) then $ line2=strmid(line,res+nst1,nline-res-nst1) line=line1+st2+line2 endfor endif newline: ;print changed lines if(mui eq 1 or mui1 eq 1 or mui2 eq 1) then begin n_change=n_change+1l if(sile lt 1) then begin print,lineori print,line print,' ' endif endif printf,2,line endwhile endi: close,1 close,2 if(sile lt 2) then print,'changed ',n_change,' lines if(ijunk eq 1) then begin cmd='cp junk '+file2_oikea spawn,cmd endif end