필터 지우기
필터 지우기

Editing a txt file and replace a specifics lines

조회 수: 1 (최근 30일)
judy abbott
judy abbott 2016년 4월 8일
댓글: judy abbott 2016년 4월 8일
Dear all, my question is about the edition of an txt file and the replacement of the 4 and the 5 line and keep the above ones and the after ones: txtfile = ZZZ.txt
Not change
Not change
Not change
TO change
TO change
Any suggestions please.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 8일
How you replace these lines?
judy abbott
judy abbott 2016년 4월 8일
i look to replace the wholes lines (the 4 and the 5) by other lines, i think to do an counter (while .. do)

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 8일
편집: Azzi Abdelmalek 2016년 4월 8일
Read your text file
fid=fopen('ZZZ.txt')
s=textscan(fid,'%s')
fclose(fid)
out=[s{:}]
Then replace whatever you want
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 8일
%lines that replace the two lines of out
line1='abc'
line2='efg'
out(4:5)={line1;line2}
fid=fopen('fic1.txt','w')
for k=1:numel(out)
fprintf(fid,'%s\n',out{k})
end
fclose(fid)
judy abbott
judy abbott 2016년 4월 8일
Ok it's done

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by