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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Bob Thompson
le 25 Sep 2018
You could work this a couple of different ways. I would suggest some form of sorting using regexp().
Réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Export 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!