参考代码:
[f,p] = uigetfile('*.*','选择输入文件','runlog');
if f==0, return, end
file = [p f];
fi = fopen(file, 'rt');
if fi == -1
error(['无法打开文件 ' file])
end
fo = fopen('reslut.dat', 'wt');
if fo == -1
error(['无法打开文件 reslut.dat'])
end
fprintf(fo,'abc\ndef\n');
ptn = 'delete number';
while ~feof(fi)
s = fgetl(fi);
inx = findstr(s, ptn);
if isempty(inx), continue, end
d = sscanf(s(inx(1)+length(ptn)+1:end),'%d');
fprintf(fo,'create,%i\n',d);
end
fprintf(fo,'ghj\nqwe\n');
fclose(fi);
fclose(fo);
搞得这么复杂。。。linux下面一条命令就搞定