perl - Multiline lookback regex -


i'm working script outputs bunch of memory values log file , need extract few specific lines relative each other.

here sample of chunk of log output:

       pool id      type      term       user/sys     total size           free        -------      ----      ----       --------     ----------           ---- 0x7fc636000000   control      long           user     1609564160      335224768       client id      memory alloc'd      (normal/small)    client name      ---------      --------------      --------------    ----------- 0x7fc636001a90             7470051       (7469056/995)    diskcontrol 0x7fc6360017d8             4067072         (4067072/0)    kjs 0x7fc636001520          1158242183 (1157640768/601415)    plu 0x7fc636001268            68499632     (68498240/1392)    splitter 0x7fc636000fb0            36665368     (36664256/1112)    backview 

i need extract plu line:

0x7fc636001520          1158242183 (1157640768/601415)    plu 

i need extract pool id

0x7fc636000000   control      long           user     1609564160      335224768 

this chunk 1 of many , there no way identify pool id grab without knowing client held (so need find plu first before find pool).

finding plu line easy:

/(.*)plu/ 

but finding pool line has proven more difficult.

i've found suggestions using multi-line regex search hasn't seemed work. have tried using lookbacks doesn't seem work.

ignoring moment necessary relation specific client , pool, tried pool line:

/(?<=----).*(?=client)/gm 

that doesn't highlight on regexr.

i'd appreciate if can give it. i'm using perl write script extracting info ( whole infrastructure in perl ).

it's bad idea read entire file memory, need split lines process , may read line line in first place

if understand correctly, need store every pool id encounter. when find plu client, relevant pool id recent 1 encountered

it this

use strict; use warnings 'all';  ($pool_id, $client_id);  while ( <data> ) {     if ( /pool id/ ) {         while ( <data> ) {             last if ($pool_id) = /^0x(\p{hex}+)/;             }     }     elsif ( /\splu\s*$/) {         ($client_id) = /^0x(\p{hex}+)/;         last;     } }  print "pool id:       $pool_id\n"; print "plu client id: $client_id\n";  __data__        pool id      type      term       user/sys     total size           free        -------      ----      ----       --------     ----------           ---- 0x7fc636000000   control      long           user     1609564160      335224768       client id      memory alloc'd      (normal/small)    client name      ---------      --------------      --------------    ----------- 0x7fc636001a90             7470051       (7469056/995)    diskcontrol 0x7fc6360017d8             4067072         (4067072/0)    kjs 0x7fc636001520          1158242183 (1157640768/601415)    plu 0x7fc636001268            68499632     (68498240/1392)    splitter 0x7fc636000fb0            36665368     (36664256/1112)    backview 

output

pool id:       7fc636000000 plu client id: 7fc636001520 

Comments