How do I extract particular column from unformatted text in .txt file

조회 수: 2 (최근 30일)
Internet Protocol, Src: 0.0.66.242 (0.0.66.242), Dst: 10.0.0.3 (10.0.0.3)
Data (22 bytes)
0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0010 00 00 00 00 00 00 ......
Time Stamp Sequence Num Packet Size Destination IP Packet Num Time Interval Protocol
0.034272 0.0.66.243 60 10.0.0.3 10 0.002262 IP
Frame 10 (60 bytes on wire, 60 bytes captured)
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: AsustekC_60:6d:80 (00:1d:60:60:6d:80)
Internet Protocol, Src: 0.0.66.243 (0.0.66.243), Dst: 10.0.0.3 (10.0.0.3)
Data (22 bytes)
0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0010 00 00 00 00 00 00 ......
Time Stamp Sequence Num Packet Size Destination IP Packet Num Time Interval Protocol
0.040435 0.0.66.244 60 10.0.0.3 11 0.006163 IP
Frame 11 (60 bytes on wire, 60 bytes captured)
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: AsustekC_60:6d:80 (00:1d:60:60:6d:80)
Internet Protocol, Src: 0.0.66.244 (0.0.66.244), Dst: 10.0.0.3 (10.0.0.3)
Data (22 bytes)
0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0010 00 00 00 00 00 00 ......
Time Stamp Sequence Num Packet Size Destination IP Packet Num Time Interval Protocol
0.043839 0.0.66.245 60 10.0.0.3 12 0.003404 IP
Frame 12 (60 bytes on wire, 60 bytes captured)
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: AsustekC_60:6d:80 (00:1d:60:60:6d:80)
Internet Protocol, Src: 0.0.66.245 (0.0.66.245), Dst: 10.0.0.3 (10.0.0.3)
Data (22 bytes)
This is my list of data from the .txt file from which I need to extract Sequence Number data which is 0.0.66.xxx. How do I do it?
  댓글 수: 4
Guillaume
Guillaume 2019년 7월 8일
편집: Guillaume 2019년 7월 8일
I do not know about the delimiter status
Attaching an example test file (as opposed to copy pasting into a browser which may or may not alter the actual characters of the file), would allow us to find out.
Note taht if you're using wireshark, it has options to export in text formats that are a lot easier to import into matlab than what you show (e.g. csv format).
dpb
dpb 2019년 7월 8일
"... wireshark ... has options to export in text formats that are a lot easier to import into matlab than what you show (e.g. csv format)."
+127

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

채택된 답변

Akira Agata
Akira Agata 2019년 7월 9일
As mentioned by many experts, it's better to save as .csv format by wireshark. But if you have to do this task from the text file for some reasons, no need to worry! :-)
% Read text file
fid = fopen('New Text Document.txt','r');
C = textscan(fid,'%s','Delimiter','\n');
C = C{1};
fclose(fid);
% Find the lines containing 'Sequence Num' and extract the next lines
idx = contains(C,'Sequence Num');
C = C([false; idx(1:end-1)]);
% Split each line with space
C = split(C);
% Extract 2nd column
seqNum = C(:,2);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품


릴리스

R2007b

Community Treasure Hunt

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

Start Hunting!

Translated by