A few details worth noting that I can think of off hand:
The solution I found first way back in 1998-1999 that worked the best was not to solve the problem in a single Regexp, but rather to use multiple Regexp looking for pieces of the puzzle.
To be more specific:
#!perl # sample string. The code below could be looped as well. # i.e. within while($string = <LMSTAT>){ } my $string = 'Users of ClearQuest: (Total of 18 licenses issued; Total + of 12 licenses in use)'; if($string =~ m/Users? of (\w+):\s+(\(.+\))/){ # must test for successful pattern match # or value may mistakenly be set to previous successful match! my $feature =$1; my $usage = $2; my $num_used=0; my $num_total=0; my $num_queued=0; if($usage =~ m/(\d+)\slicenses? (in use|Used)/ # handles variation +s in Used Licenses ){ $num_used=$1; } if($usage =~ m/(\d+)\slicenses? (issued|available)/ # handles vari +ations in Total Licenses ){ $num_total=$1; } if($usage =~ m/(\d+)\slicenses? (queued)/ # handles Queued license +s ){ $num_queued=$1; } # more IF statements to test for queued, reserved, etc. print "lmstat output: $string\n"; print "feature name: $feature\n"; print "usage string: $usage\n\n"; print "Total $feature Licenses: $num_total\n"; print "Total $feature Used Licenses: $num_used\n"; print "Total $feature Queued Licenses: $num_queued\n"; my $num_free=$num_total-$num_used-$num_queued; print "Approximate Free $feature Licenses: $num_free\n"; } else { # not a "Usage" line. Perhaps parse out # the USERNAMES of each used license here... }
This should directly solve your problem, and prepare you for any hangups that may await you. Like Perl, with FlexLM there is 'more than one way to do it' so keep this in mind.
If you need further help, you can message me privately. I've used Perl to populate a data warehouse with these sort of data. Getting control over license usage is a great way to reduce software costs.
In reply to Re^2: Regex to extract number from text file
by spectre9
in thread Regex to extract number from text file
by premal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |