what perl regex should I use to get value from line

Posted by Octopus on Stack Overflow See other posts from Stack Overflow or by Octopus
Published on 2010-04-08T08:34:32Z Indexed on 2010/04/08 8:43 UTC
Read the original article Hit count: 408

Filed under:
|

I am trying to capture the cpu usage from the running process. For SunOS, I have below output

process,10050,user1,218,59,0,1271M,1260M,sleep,58.9H,0.02%,java

here the cpu % is at 11th field if we separate by comma(,). To get this value I am using below regex

regex => q/^process,(?:.*?),((?:\d+)\.(?:\d+))%,java$/,

but for the linux system I have below output.

process,26190,user1,20,0,1236m,43m,6436,S,0.0,1.1,0:00.00,java,

here the cpu usage is at 10th column

What regex pattern should i use to get this value. Appreciate for any suggestion.

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex