MATLAB: Extract useful info from text file filled with irrelevant info

extractirrelevant infotextfiletxt

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

Best Answer

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