Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

4 vues (au cours des 30 derniers jours)
Zubier  Abdullah
Zubier Abdullah le 1 Août 2017
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaires
Stephen23
Stephen23 le 1 Août 2017
@Zubier Abdullah: what have you tried so far?
Zubier  Abdullah
Zubier Abdullah le 4 Août 2017
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.

Réponses (1)

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

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by