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: 375

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:


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:


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