我有大文本文件,里面有很多信息。我只需要访问一个以'***'标记的行。该行包含17个数字,它们之间有空格。
文件示例是,
Msg count = 2629
max send msg count = 34
avg send msg count = 10.27
imbalance send msg count = 3.31
------------------------------
max recv msg count = 35
avg recv msg count = 10.27
imbalance recv msg count = 3.41
***1.100020 306852 1381937 11045 5398.19 2.05 10465 5398.19 1.94 2629 34 10.27 3.31 35 10.27 3.41 0.000000
[INFO] +++ Sat Sep 24 15:15:33 2016
+++ (test.c:816) stat1 end
有办法做到这一点吗?
答案 0 :(得分:0)
尝试使用此代码:
infilename = 'nameoffile.txt'; % name of your file
m = memmapfile(infilename); % load file to memory (and after close it)
instrings = strsplit(char(m.Data.'),'\n','CollapseDelimiters',true).';
checkstr = '***';
% find all string (their indices) starting with checkstr
ind = find(strncmpi(instrings,checkstr,length(checkstr)));
if isempty(ind)
fprintf('\n No strings with %s',checkstr)
else
% first string with string checkstr
instrings(ind(1));
end