Merging specific rows from multiple text files.
1 回表示 (過去 30 日間)
古いコメントを表示
I have time series data for a day, split into roughly 5 minute segments each of which is in a separate txt file, each with several rows of headers and information above the data.
Hence I want to merge all 198 txt files to one txt file with only the continuous timeseries data. How can I merge the files, removing the 30 rows of unnecessary information from the top of each.
I have had success merging them all together using the code below, but that is without removing the initial 30 rows from each .txt file
files=dir('*.txt');
fileout='merged.txt';
fout=fopen(fileout,'w');
for cntfiles=1:length(files)
fin=fopen(files(cntfiles).name);
while ~feof(fin)
fprintf(fout,'%s %d\n',fgetl(fin),cntfiles);
end
fclose(fin);
end
fclose(fout);
0 件のコメント
採用された回答
Guillaume
2016 年 11 月 29 日
I don't see where the difficulty is in modifying your code to skip the writing of the first 30 lines of each file:
%...
fin=fopen(files(cntfiles).name);
linecount = 0;
while ~feof(fin)
linecount = linecount + 1;
linetext = fgetl(fin);
if linecount >= 31 %The first 30 lines are header lines that should be skipped
fprintf(fout, '%s %d\n', linetext, cntfiles);
end
end
%...
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!