Editing a txt file and replace a specifics lines
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
judy abbott
le 8 Avr 2016
Commenté : judy abbott
le 8 Avr 2016
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 commentaires
Réponse acceptée
Azzi Abdelmalek
le 8 Avr 2016
Modifié(e) : Azzi Abdelmalek
le 8 Avr 2016
Read your text file
fid=fopen('ZZZ.txt')
s=textscan(fid,'%s')
fclose(fid)
out=[s{:}]
Then replace whatever you want
3 commentaires
Azzi Abdelmalek
le 8 Avr 2016
%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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!