It appears you are trying to parse the output of the FlexLM 'lmstat' command. I've tackled that problem before.

A few details worth noting that I can think of off hand:

  • The 's' after the word licenses should be marked optional with a ? in the regexp.
  • Licenses can be "Reserved" and "Queued" as well, if my memory served, those are the strings one sees.
  • The lmstat output itself can vary in format on a per-feature basis. The lmstat tool is merely passing on data from the "vendor daemons" and the format varies quite a bit.

    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:

  • Parse the license/feature name out of the string, and strip out the part that follows with the 'usage' data into a new string.
  • Parse the 'usage' string and look for the pieces you need. Handle the variations if they occur in your data. Code example:

    #!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.

    spectre#9 -- "Strictly speaking, there are no enlightened people, there is only enlightened activity." -- Shunryu Suzuki

    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

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.