How can I copy lines of an external text file to another file
40 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I would like to know how can I open a file, named a.txt (which in attach), and copy all the lines, from the line 5 to the end of file, to another text file, named b.txt
I thank you in advance,
Best regards,
0 commentaires
Réponses (2)
Voss
le 26 Avr 2022
Here's one way:
fid_in = fopen('a.txt'); % input file
fid_out = fopen('b.txt','w'); % output file
for ii = 1:4 % read (and discard) the first four lines
fgetl(fid_in);
end
data = fread(fid_in); % read the rest of the input file
fclose(fid_in); % close the input file
fprintf(fid_out,'%s',data); % write data to the output file
fclose(fid_out); % close the output file
type b.txt % check the contents of b.txt
0 commentaires
Voir également
Catégories
En savoir plus sur Text Files 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!