extract useful info from text file filled with irrelevant info
2 views (last 30 days)
The text files that I have are like this: useless info... * useful date (within useless info) useful info *useless info and like that until the end - if there a way of extracting the useful stuff rather than copy and pasting each individual one (as each file has like 200 things to copy into excel) ? Thanks
Guillaume on 6 Aug 2016
Edited: Guillaume on 6 Aug 2016
Now that we finally know what useful and useless look like, we can finally answer the question (mostly).
Here is one way to extract the LPR section(s):
filecontent = fileread('example2.txt');
filesections = regexp(filecontent, 'File name.*?(?=(File name)|$)', 'match'); %match 'File name' and everything that follows up to the next 'File name' or the end of string.
testtypes = regexp(filesections, '(?<=Test type\s*)\S+', 'match', 'once'); %match non-blank characters after 'Test type'
wantedsections = filesections(strcmp(testtypes, 'LPR'));
edit: missing ) in first regex
More Answers (1)
Shameer Parmar on 29 Jul 2016
use this command..
Data = textread('FileName.txt', '%s', 'delimiter', '');
then apply the logic (FOR and IF loop) according to your requirement for reading and storing the data..
Please provide the data of your text file and about the required data so that I can help you for logic..