Paul,
I always make it a point to thank/recognise those who have helped me. I got tied up with a couple emergencies yesterday otherwise I would have responded sooner…I apologize.
Anyways,
Thank you to everyone who helped me yesterday, my understanding of regex is a little better now. Special thanks to Toolkit for breaking things down into a simpler form and pointing out my mistakes.
I’m working on an inventory project where I have to collect the CPU information for several SUN Servers that display their CPU information as follows:
Data file 1 (4 CPU's)
___DATA___
Brd CPU Module MHz MB Impl. Mask
--- --- ------- ----- ------ ------ ----
SYS 0 0 400 4.0 US-II 10.0
SYS 1 1 400 4.0 US-II 10.0
SYS 2 2 400 4.0 US-II 10.0
SYS 3 3 400 4.0 US-II 9.0
___DATA___
or as in my original example:
Data file 2 (1 CPU)
___DATA___
Brd CPU Module MHz MB Impl. Mask
--- --- ------- ----- ------ ------ ----
0 0 0 360 0.2 12 9.1
___DATA___
My immediate requirement was the CPU count, so in the end I used the following regular expressions to count each line in the data file, which worked!
For data file 1
(/^[A-Z]{3}\s{1,}([0-9]{1,}\s{1,}){3}[0-9]{1,}\.[0-9]{1,}\s{1,}[A-Z]{1,}-[A-Z]{1,}\s{1,}[0-9]{1,}\.[0-9]{1,}/)
For data file 2
(/^\s([0-9]{1,}\s{1,}){4}[0-9]{1,}\.[0-9]{1,}\s{1,}[0-9]{1,}\s{1,}[0-9]{1,}\.[0-9]{1,}/)
I’m sure the expression could be more efficient but I thought I would come up with my own work first (based on the examples provided) then look at the answers provided and tweak later…
Thanks again folks!
Stickybit