How to read multi .txt files and extract files which are started with the specific name and write all these files in a new .txt file?
1 次查看(过去 30 天)
显示 更早的评论
I have around 10000 .dat files. Their names are like this :
tag-klima-500-1987-1_12.dat ; tag-klima-500-1987-1_12.dat ; tag-klima-905-1987-1_12.dat ; tag-klima-905-1987-1_12.dat
I need to read those files with the same middle number, for example, all those that have 500 , or 905 in the middle. And then write all data belong to each group (groups which have identification of 500 or 905) in a .txt file.
I could read and write for files belong to each group, for example for files starting with tag-klima-905, but I have stuck to do it for all file at the same time when running the codes.
pth = 'E:\DATA\Agro\ZAMG\klima-ehsan-1987_2017';
fileList = dir(fullfile(pth, 'tag-klima-905*.dat'));
out = fopen(fullfile(pth, 's905.txt'), 'w');
delimiter = '\t';
startRow = 2;
formatSpec = '%s%s%s%s%s%s%s%[^\n\r]';
for k = 1:numel(fileList)
s = fileread(fullfile(pth, fileList(k).name));
fwrite(out, s, 'char');
end
fclose(out);
I appreciate any helps,
1 个评论
Bob Thompson
2018-9-25
You could work this a couple of different ways. I would suggest some form of sorting using regexp().
回答(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!