Editing a txt file and replace a specifics lines

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 comentarios

How you replace these lines?
judy abbott
judy abbott el 8 de Abr. de 2016
i look to replace the wholes lines (the 4 and the 5) by other lines, i think to do an counter (while .. do)

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 8 de Abr. de 2016
Editada: Azzi Abdelmalek el 8 de Abr. de 2016
Read your text file
fid=fopen('ZZZ.txt')
s=textscan(fid,'%s')
fclose(fid)
out=[s{:}]
Then replace whatever you want

3 comentarios

judy abbott
judy abbott el 8 de Abr. de 2016
@ Azzi, it work for edition, how i keep the above lines and the next one and to save them in the same (ZZZ.txt) file
%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 el 8 de Abr. de 2016
Ok it's done

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 8 de Abr. de 2016

Comentada:

el 8 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by