Info

此问题已关闭。 请重新打开它进行编辑或回答。

How do I remove the first 3 lines from all of the .txt files in a directory?

4 次查看(过去 30 天)
Hello everyone
I am trying to preprocess a large batch of text files in Matlab. To do this, I have to remove the first couple of lines from each of the files. Can anyone share me some code on how to do this? Thanks
  3 个评论
Zubier  Abdullah
Zubier Abdullah 2017-8-4
this is the code i am using so far
files = dir('*.TXT') N = numel(files) count = 0;
for i = 1:N fid1 = files(i).name disp(fid1) a = fopen(fid1,'r') file_name = [sprintf('%1.0f',i) '.txt']; fopen(file_name,'w+');
for K = 1:4
inline = fgetl(a)
end
while ischar(inline)
inline = fgetl(a)
fprintf(file_name,'%s\n\r',inline)
end
fclose('all')
end
so far it is only creating blank files and not replacing the content of the files as i wanted. I have a smaller program where it replaces the text from one file to another but i have already defined the names.

回答(1 个)

ES
ES 2017-8-1
You can start here ... https://in.mathworks.com/matlabcentral/fileexchange/42877-find-and-replace-in-files

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by