MATLAB Answers

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

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 Comments

Show 1 older comment
The one I have put in the question is the example text file. It goes all the way to 100,000 pages but I just put up 4 columns of the text file. The formatting is exactly as shown above. The baove data were generated by Wireshark, a tool used to monitor wireless packets. I do not know about the delimiter status. Whatever delimiter was generated by wireshark, can be either space bar or can be just tab.
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).
"... 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

Sign in to comment.

Products


Release

R2007b

1 Answer

Answer by Akira Agata
on 9 Jul 2019
 Accepted Answer

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 Comments

Sign in to comment.