Log Parsing using MATLAB

조회 수: 4 (최근 30일)
Joshua Mikhael Prieto
Joshua Mikhael Prieto 2020년 10월 27일
댓글: Ruben Ruiloba 2021년 8월 28일
Hello! Can someone help me with log parsing a file? I did searched videos and I get some parts of it like importing.
For example this is my file (data_file.txt)
98.140.180.244 - harber4797 [21/Jun/2019:16:01:53 -0700] "POST /seize/b2b/synergistic HTTP/2.0" 203 9396
54.92.231.149 - ziemann5634 [21/Jun/2019:16:01:54 -0700] "GET /revolutionize/matrix HTTP/2.0" 304 27968
205.98.120.209 - trantow6874 [21/Jun/2019:16:01:39 -0700] "PUT /front-end/world-class/partnerships/schemas HTTP/1.0" 401 25144
148.196.48.243 - ondricka6863 [21/Jun/2019:16:01:40 -0700] "GET /best-of-breed/reinvent HTTP/1.1" 501 29641
130.229.174.187 - hackett3055 [21/Jun/2019:16:01:41 -0700] "GET /sticky/deliver HTTP/2.0" 404 5708
if I input 'harber4797' to a function, how can I extract its whole line? What conditional works should I do? Thank you

답변 (2개)

Walter Roberson
Walter Roberson 2020년 10월 27일
편집: Walter Roberson 2021년 8월 28일
S = fileread('data_file.txt');
line_matches = regexp(S, '^.*\sharber4797\s.*$', 'lineanchors', 'dotexceptnewline')

Ruben Ruiloba
Ruben Ruiloba 2021년 8월 27일
I get an error Matrix dimensions must agree. when I run
line_matches = regexp(S< '^.*\sharber4797\s.*$', 'lineanchors', 'dotexceptnewline')
Not sure why.
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 8월 28일
Sorry about that. < is shift-comma on my keyboard, and I wanted a comma at that point instead of a <

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by