Extract specific values from a text file corresponding to a string
1 次查看(过去 30 天)
显示 更早的评论
I have the log file as stated below. I want to search for the occurences of the following line containing : imxv4l2videosrc0_src. And later extract the value `fps`, to plot them as a graph. Can anyone provide some pointers on how to do this?
0:00:02.249654647 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)pay0_src, fps=(uint)44;
0:00:02.249798648 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)imxv4l2videosrc0_src, fps=(uint)22;
0:00:02.249937982 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)h264parse0_src, fps=(uint)21;
0:00:02.250077650 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)send_rtp_sink_0_proxypad1, fps=(uint)47;
0:00:02.250217318 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)rtpbin_send_rtp_src_0, fps=(uint)47;
0:00:02.250353319 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)imxvpuencoderh264_0_src, fps=(uint)21;
0:00:02.250492320 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)queue1_src, fps=(uint)44;
0:00:02.250631321 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)queue0_src, fps=(uint)22;
0:00:03.249094861 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)rtpsession0_send_rtp_src, fps=(uint)59;
0:00:03.249463531 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)queue2_src, fps=(uint)59;
0:00:03.249620532 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)pay0_src, fps=(uint)60;
0:00:03.249761533 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)recv_rtcp_sink_0_proxypad3, fps=(uint)1;
0:00:03.249901201 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)imxv4l2videosrc0_src, fps=(uint)27;
0:00:03.250039202 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)h264parse0_src, fps=(uint)28;
0:00:03.250175869 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)send_rtp_sink_0_proxypad1, fps=(uint)59;
0:00:03.250314537 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)rtpbin_send_rtp_src_0, fps=(uint)59;
0:00:03.250451538 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)imxvpuencoderh264_0_src, fps=(uint)28;
0:00:03.250587873 [332m 1465[00m 0x19cfce0 [37mTRACE [00m [00;34m GST_TRACER :0::[00m framerate, pad=(string)queue1_src, fps=(uint)60;
0 个评论
回答(1 个)
Adam Danz
2018-11-29
编辑:Adam Danz
2018-11-29
Here's one approach.
"I want to search for the occurences of the following line containing : imxv4l2videosrc0_src".
1. Load your log file into matlab using one of the methods in the link. Perhaps textscan() is best. Given your task, it would be easiest if your data were organized in a cell array where each element is a line in your log file but there are lots of alternatives to how you can organize the data.
2. Assuming the data are organized by row, you can use regexp() , strfind() , or contains() to search for which rows have the substring "imxv4l2videosrc0_src".
3. You want an index of elements that contain this substring. The contains function gives this to you directly. The regexp and strfind functions will return empties within a cell array if an element does not contain the search phrase. So, to identify which elements do contain the phrase, use this (below) where 'output' is the output of the regexp or strfind function and 'containsPhrase' is a logical vector identifying which elements contain the phrase.
containsPhrase = ~cellfun(@isempty, output);
"And later extract the value `fps`, to plot them as a graph"
I have no idea which column in your data are fps. The section above will give you the relevant rows of your log file to extract from. There are lots of ways to pull out a section of each row - especially if the rows have the same format. You'll likely use regexp() again but there might be even easier methods depending on what fps is.
2 个评论
Adam Danz
2018-11-29
It's really hard for me to imagine what your variables are here. What is Cd? Could you give me an example of what the variable looks like?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!