How can select apecific rows from text files

Hi , i have theses data sets as text file,
i need extract and save specific rows only ( i need the rows that contains the words : ReadReq or WriteReq , ( otherwise negleget all other rwos !)
example: i need extrect the rows contain on the words inside its ( readReq or Writereq) such as :
3411151194500: system.cpu04.icache: ReadReq [380730:380733] IF hit state: 7 (E) valid: 1 writable: 1 readable: 1 dirty: 0 tag: 1c0
3411151194500: system.cpu04.dcache: WriteReq [a22a48:a22a4f] miss
from the original text file :
3411151194500: system.cpu04.icache: ReadReq [380730:380733] IF hit state: 7 (E) valid: 1 writable: 1 readable: 1 dirty: 0 tag: 1c0
3411151194500: system.cpu04.dcache: createMissPacket: created ReadExReq [a22a40:a22a7f] from WriteReq [a22a48:a22a4f]
3411151194500: system.cpu04.dcache: WriteReq [a22a48:a22a4f] miss
3411151194500: system.cpu04.dcache: recvAtomic: Sending an atomic ReadExReq [a22a40:a22a7f]
3411151194500: system.cpu04.dcache: Block addr 0xa22a40 (ns) moving from state 0 to state: 7 (E) valid: 1 writable: 1 readable: 1 dirty: 0 tag: 511
I appriciate for any hepl please

1 commentaire

Guillaume
Guillaume le 23 Oct 2019
I'd recommend you go over the questions asked by this guy because I've answered several question of his that dealt with parsing log files very similar to yours.

Connectez-vous pour commenter.

 Réponse acceptée

% Read all your data into a cell array. 'Delimiter','' means to import
% everthing into one column, which I believe is better for your
% application.
data = readcell('data.txt','Delimiter','');
% Create a vector 'TF' that identifies logically which rows in 'data'
% contain the strings you identified. "|" represents the 'or' function.
TF = contains(data,('WriteReq')) | contains(data,('ReadReq'));
% for every element of 'data' where TF is zero (false, i.e. doesn't contain
% either string) set that value to '[]' to delete it from the array.
data(TF == 0) = [];

5 commentaires

Thanks alot for your help , really i appreciate
but still take the error rows!
becuase we need check (Readreq, writereq ) after third term beyond the (:) sign for each row (time :X:X:X ....)
Then you'll need to do it a little different.
I don't know what exactly you're trying to end up with, and which rows you are calling errors, but here are some options on how to proceed. Each option will give you a different result. The "right" one is for you to decide.
Option 1:
look for 'valid' instead of ('WriteReq' or 'ReadReq'). But I'm not sure if that works for your application; that's up to you.
Option 2:
change ('WriteReq' or 'ReadReq') to (': WriteReq' or ': ReadReq')
Option 3:
Change the delimiter from:
''
to this:
{': '}
or this:
{': ','[',']'}
(depending on which you like the results of better)
Then only search for that string on column 3, and delete the rows as we did before.
Then create another TF query for 'miss', and take the 'not'. Like this:
TF2 = not(contains(data(:,5),('miss')))
Depending on the delimiters you chose above, you may need to change '5' to '3' to search the correct column.
Now, I'm assuming you don't want rows with the word 'miss' in it. So this line will search like before for the word 'miss' and return a true/false array. But since we DON'T want the word 'miss' you take the 'not' of it and only keep the rows that don't include 'miss'.
The rest is up to you based on which option gives you the results you expect.
Thanks alot for your generosity clarification , i solved it . thanks too much.
Glad you got it working. If you're satisfied with this answer, please click the "accept" button.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by