Delete rows in single .txt files
1 次查看(过去 30 天)
显示 更早的评论
Hey,
I have 30 .txt files where I would like to delete always the first three rows before creating one file for all 30 files...?
Thanks already!
Best!
0 个评论
回答(1 个)
Image Analyst
2014-7-5
Before the loop open a file for output.
fOutput = fopen('output.txt, 'wt');
Then go into the loop opening the files (as per the FAQ). Call fgetl() three times and throw away/ignore the text you get back. Then continue on to the end of the file transferring the stuff to the output file
textLine = fgetl(fInput);
fprintf(fOutput, '%s\n', textLine);
Finally when all lines have been transferred, call fclose(fInput). Then when the loop is done, call fcope(fOputput). It's really easy - give it a try.
Sounds a little like homework, so I didn't just do the whole thing for you, even though it's trivial.
1 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!