필터 지우기
필터 지우기

Delete lines n to m in many text files

조회 수: 4 (최근 30일)
H R
H R 2017년 7월 11일
편집: Jan 2017년 7월 11일
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.

채택된 답변

Jan
Jan 2017년 7월 11일
편집: Jan 2017년 7월 11일
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

추가 답변 (1개)

KSSV
KSSV 2017년 7월 11일

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by