How can select apecific rows from text files

조회 수: 1 (최근 30일)
Furat Alobaidy
Furat Alobaidy 2019년 10월 23일
댓글: Joe Vinciguerra 2019년 10월 24일
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
Guillaume
Guillaume 2019년 10월 23일
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.

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

채택된 답변

Joe Vinciguerra
Joe Vinciguerra 2019년 10월 23일
% 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
Furat Alobaidy
Furat Alobaidy 2019년 10월 23일
Thanks alot for your generosity clarification , i solved it . thanks too much.
Joe Vinciguerra
Joe Vinciguerra 2019년 10월 24일
Glad you got it working. If you're satisfied with this answer, please click the "accept" button.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by