Delete lines n to m in many text files

1 vue (au cours des 30 derniers jours)
H R
H R le 11 Juil 2017
Modifié(e) : Jan le 11 Juil 2017
Hello there,
I have 500 text files with names R1.txt to R500.txt.
How can delete lines 5002 to 5012 from all the text files and save them in the same text files?
Many thanks.

Réponse acceptée

Jan
Jan le 11 Juil 2017
Modifié(e) : Jan le 11 Juil 2017
folder = '???'
for iFile = 1:500
% Create file name:
File = fullfile(folder, sprintf('R%d.txt', iFile));
% Import file and modify the contents:
DataC = strsplit(fileread(File), '\n');
DataC(5002:5012) = [];
% Overwrite the file:
fid = fopen(File, 'w');
if fid == -1
error('Cannot open file for writing: %s', File);
end
fprintf(fid, '%s\n', DataC{:});
fclose(fid);
end

Plus de réponses (1)

KSSV
KSSV le 11 Juil 2017

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by