parsing - Parse specific output into variables Java -


i trying find best way how parse specific output jsch when connecting , executing commands on c7000 hp enclosure.

what have done far written program connects hp enclosure, executes command, retrieves output of command , converts stream string.

i end string

 server blade #1 information:     type: server blade     manufacturer: hp     product name: proliant bl280c g6     part number: 507865-b21          system board spare part number: 531337-001     serial number: xz73616g9z           uuid: 38926035-5636-5d43-3330-359274423959     server name: serverone     asset tag: [unknown]     rom version: i25 02/01/2013      cpu 1: intel(r) xeon(r) cpu e5520 @ 2.27ghz (4 cores)     cpu 2: intel(r) xeon(r) cpu e5520 @ 2.27ghz (4 cores)     memory: 49152 mb 

now need extract information string , put in variable/variables. have tried regex don't seem hack it. need end example, product name "proliant bl280c g6" in string variable later can use, same goes serial number or other info in there. not need preceding text type: or part number:. need extract comes after that.

i pretty new java, learning lots every day, can here point me in right direction of best way of solving this?

edit: thank quick responses. got few ideas on how solve problem. biggest goes showing me how use regex expressions correctly. missed there possibility of excluding string pieces not needed ex. (?<=product\sname:).

string delims = "\n";   //this identifier of line change in java string[] lines = result.split(delims);    (int i=0;i<lines.length;i++)   {           system.out.println(lines[i]);   }   

this code save (and print) lines in string (assuming posted saved java string).

you have several ways thou. sure more reasonable methods make (regex, parsers,...), can check if string contains substring:

 str1.tolowercase().contains(str2.tolowercase()) 

so, example, if want know if line of lines[i] contains word product name, make this:

 subs = "product name";  if (lines[x].tolowercase().contains(subs.tolowercase()));   //x being number between 0 , total of lines 

as stated, rustical method, work.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -