How can I extract a value from comma separated values in Perl?

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 9:33 UTC
Read the original article Hit count: 500

Filed under:
|

I have a log file containing statistics from different servers. I am separating the statistics from this log file using regex only. 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 commas (,). To get this value I am using below regex:

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

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?

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex