Create function to extract data from .log file

Dear all,
I want to write a function can extract data from log file. It like that
The number marked yellow is the number what I want to output and then used to do the calculate. I would really appreciate that if anyone can provide any help.
Thanks in advance.

 채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 28일

1 개 추천

S = fileread('NameOfYourLogFileGoesHere.log');
value_of_interest_string = regexp('(?<=it\.it-nin\.icytot\.nrep2\.mtfail\.IMPES:\s*)\S+', 'match');
value_of_interest = str2double(value_of_interest_string);
This code does not assume that the value is an integer, just that it appears after the mtfail.IMPES: string and ends in whitespace.

댓글 수: 7

Cedric
Cedric 2017년 9월 28일
편집: Cedric 2017년 9월 28일
It would probably work with the shorter pattern:
'(?<=IMPES:\s*)\S+'
Probably Yes ;-) But just in case there is another IMPES: in the file...
Cedric
Cedric 2017년 9월 28일
편집: Cedric 2017년 9월 28일
That's not IMPESsible! ;-)
Thanks a lot. I just run this code return the NaN. I will take a look of the regexp function. Thanks again.
Cedric
Cedric 2017년 9월 28일
편집: Cedric 2017년 9월 28일
There is a typo that I didn't spot: the first argument in the call to REGEXP should be the content to parse, which is variable S. Try with the following:
S = fileread('NameOfYourLogFileGoesHere.log');
value_of_interest_string = regexp(S, '(?<=it\.it-nin\.icytot\.nrep2\.mtfail\.IMPES:\s*)\S+', 'match');
value_of_interest = str2double(value_of_interest_string);
and/or with the simpler pattern that I proposed:
S = fileread('NameOfYourLogFileGoesHere.log');
value_of_interest_string = regexp(S, '(?<=IMPES:\s*)\S+', 'match');
value_of_interest = str2double(value_of_interest_string);
Thanks a lot. It really help a lot. I also solved a way
Str = fileread('WH Generated path_09.log');
Key = 'it,it-nin,icytot,nrep2,mtfail,IMPES:';
Index = strfind(Str,Key);
Value =sscanf(Str(Index(1)+length(Key):end),'%g',1);
Yes, sorry, I missed the S in the regexp call.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2017년 9월 28일

댓글:

2017년 9월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by