0

I have the following output from FlexLM (lmstat -a) :

Users of server:  (Total of 5 licenses issued;  Total of 4 licenses in use)

"feature1" v9.0, vendor: klocwork
floating license

tyoung host01 /dev/tty (v9.0) (flex1.com/27000 57756), start Mon 3/21 9:06       (linger: 1209600)
jfall host02 /dev/tty (v9.0) (flex1.com/27000 17731), start Fri 3/18 12:54 (linger: 1209600)
jfall host03 /dev/pts/1 (v9.0) (flex1.com/27000 29438), start Thu 3/24 9:33 (linger: 1209600)
jfall host04 /dev/tty (v9.0) (flex1.com/27000 12791), start Thu 3/24 13:39 (linger: 1209600)

Users of client:  (Total of 10 licenses issued;  Total of 5 licenses in use)

"feature2" v9.0, vendor: klocwork
floating license

jfall host04 /dev/tty (v9.0) (flex1.com/27000 127), start Thu 3/24 13:39 (linger: 1209600)

And I'd like to get an output using like

jfall feature1 17731
jfall feature1 29438
jfall feature1 12791
jfall feature2 127

I have some preference doing that using bash and/or Python. Please note that this output could be changed at any time, some users can check out feature1 or feature2. That's why I having hard time trying to find a pattern to parse.

Any help is appreciated

Current status:

$USER="jfall"
$LOGFILE="mylog.log"
HANDLE=(`cat $LOGFILE | grep $USER | awk '{print $6}' | tr -d '),'`)
HANDLE_LENGHT=${#HANDLE[@]}
for ((i=0; i<${HANDLE_LENGHT};i++))
    do
            echo "$USER ${HANDLE[$i]}"
    done

Output :

jfall 17731
jfall 29438
jfall 12791
jfall 127

But I have no idea how I can get the list of feature assigned for each row. My first idea was to return the pattern starting by "" above each result, but I'm not sure how to implement it

2
  • 1
    Looks like you need some code.. We'd gladly help if you show some efforts in doing this. If you got stuck in your attempt, we'll help you with it! Commented Nov 17, 2013 at 1:35
  • I more looking for an idea rather than a example. As I said, I already parse the username/handle number, but I'm not sure how to get the feature assigned to each row. Anyway, I've updated my main question :) Commented Nov 17, 2013 at 2:08

1 Answer 1

3

Alright so what you need to do is break it apart on the commonalities that you see.

I see that there is a line that specifies User of... and the next line with content has the name of the feature wrapped in quotes:

#string = the example you gave
import re
sections = [x.strip() for x in re.split(r'Users of.*',string) if x != '']

the rest will be done in one loop. Assume that the rest is inside for section in sections

now we need to get the title of each section:

title = section.split('\n')[0].split('"')[1]
#get first line, get everything between first quotation marks

now you need to analyze each line to grab the names and numbers you need:

for line in section.split('/n'):
    t = re.match(r'(.*?)\s.*?\(flex1.com/\d+? (\d+)?\)',line)

the last thing that you wanted is to return only a specific starting name:

the_name = "jfall"
if t != None:
    final = [x[0] + " " + title + " " + x[1] for x in t.groups() if x[0] == the_name]

lets hold all the results in a final array called result

result += final

fully compiled loop:

import re
sections = [x.strip() for x in re.split(r'Users of.*',string) if x != '']
result = []
the_name = "jfall"
for section in sections:
    lines = section.split('\n') 
    title = lines[0].split('"')[1]
    for line in lines[1:]:
        t = re.match(r'(.*?)\s.*?\(flex1.com/\d+? (\d+)?\)',line)
        if t != None:
            final = [x[0] + " " + title + " " + x[1] for x in t.groups() if x[0] == the_name]
            result += final

now I ran this and this is what it prints:

>>> for i in result:
...     print i
... 
jfall feature1 17731
jfall feature1 29438
jfall feature1 12791
jfall feature2 127

Let me know if anything is unclear!!

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! I rather want to go with bash first, so I'll follow your guide and adapt your code to bash !
Yeah I am not familiar with bash, but the concept is the same. Take what you know will be consistent and apply regex and searches based on the consistencies to grab the inconsistencies!
Some updates : I finally gave up using Bash to do that :) I had to tweak your code to make it works with my environment, but your help was greatly appreciated and your example helped me to understand some basic tricks with Python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.