Effacer les filtres
Effacer les filtres

how to delete header and footer from dat. file?

5 vues (au cours des 30 derniers jours)
Mainul Hoque
Mainul Hoque le 30 Oct 2014
Commenté : Mainul Hoque le 4 Nov 2014
Hi!
I have 5000 dat. file. Each file have 3 header and 3 footer. I need to delete header and footer from each file and then save it again as dat. file.
Can anybody kindly tell me what is the procedure.
Regards
Mainul

Réponse acceptée

Orion
Orion le 30 Oct 2014
Hi,
i guess you need more or less this kind of code :
for i = 1:5000
FileToRewrite = ['DatFile_' num2str(i) '.dat'];
% phase 1 : read the ith dat file
fid = fopen(FileToRewrite,'r');
TextDat = textscan(fid,'%s','delimiter','\n');
fclose(fid);
% phase 2 : just take from the 4th line (3 headers) until the end-3
% (3 footers)
NewTextDat = TextDat{1}(3+1:end-3);
% phase 3 : rewrite the file with the new data
fid = fopen(FileToRewrite,'wt');
fprintf(fid,'%s\n',NewTextDat{:});
fclose(fid);
end
Big Warning : once you run this code, all you .dat files will be rewritten. think to make copies of your originals, in case there is a bug.
  1 commentaire
Mainul Hoque
Mainul Hoque le 4 Nov 2014
Hi Orion,
Thank you very much for your answer. It's really helpful and work very well.
Cheers!!!!
Mainul

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB 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!

Translated by