Python:Picking values from a table


 
Thread Tools Search this Thread
Top Forums Programming Python:Picking values from a table
# 1  
Old 01-30-2013
Python:Picking values from a table

Hi

I trying to write a python script that executes a command to screen scrub results below
I will appreciate it very much if you can help me with a python script that can
pick the percentage USAGE in the second column based on the supplied queue number in the first column
Thanks in advance.

Code:
NUMBER of Queues = 5
SYSTEM Treshold = 80%
  ==================================================================

QUEUE   USAGE   TOTAL book1   book2

------------------------------------------------------------------

0001 18%   822   481    98  

0002 16%   345   765    88  

0003 10%   400   300   166  

0004 15%   994   322    177  

0005 17%   348   297    131  

----------------------------------------------------------

---------- Post updated at 09:57 PM ---------- Previous update was at 05:50 PM ----------

I was able to get this screen scrub done using php preg_match_all
but i want to do the same with the re module in python.

Please suggestions and help will be very much appreciated

Thanks

Last edited by Scrutinizer; 01-31-2013 at 02:24 AM.. Reason: code tags
# 2  
Old 01-31-2013
Please post what you've tried so far, and hopefully a Python expert here on the forums will be able to tell you where you're going wrong.
# 3  
Old 01-31-2013
I am a complete newbie when it comes to Python. But i did it in php using

Code:
preg_match_all('/^(\d+)\s+(\d+)%/m', $content, $match, PREG_PATTERN_ORDER);
print_r($match[2][0]);

thats where i am now with it. I only Python has a re module that can do the same thing as preg_match_all in php

Thanks and help very much appreciated

---------- Post updated at 09:08 PM ---------- Previous update was at 05:29 PM ----------

I tried to do this in Python with this code but nothing shows up when i run it from the command line. Will very much appreciate your help.

Code:
import re
content = """NUMBER of Queues = 5
SYSTEM Treshold = 80%
  ==================================================================

QUEUE   USAGE   TOTAL book1   book2

------------------------------------------------------------------

0001 18%   822   481    98  

0002 16%   345   765    88  

0003 10%   400   300   166  

0004 15%   994   322    177  

0005 17%   348   297    131  

---------------------------------------------------------- """

m = re.match("(0001)/(\d{%})", content)           
if m:
    print m.group(0)      
    print m.group(1)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python Script to take file count and insert into DB2 table

Team I have files in different directories . How can i take the count of latest file and insert into Db2 table . I am using awk 'END{print NR+1-ARGC}' (File name) to get the counts. How can i take 1.The count of latest file 2.Insert into Db2 table( File Name and Counts) . cd... (4 Replies)
Discussion started by: Perlbaby
4 Replies

2. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

3. Shell Programming and Scripting

Put repeated values into a table

Hi all, I have blocks of records like the following, each block ends in = in a new line, I want tabularize the entire output. The pattern is the same in every block although not all types are there in every block. For example gine3 is absent in the second block but present first and third. ... (7 Replies)
Discussion started by: ritakadm
7 Replies

4. Shell Programming and Scripting

Perl: Writing table values to a file

I have a file like this, 1,a,saurav 2,b,rout I want to show this file in a perl cgi page table and want to add a column which will contain a text box. There I will give some manual input, which will be written to the existing file(or a new file) in below format. 1|a|saurav|bangalore... (2 Replies)
Discussion started by: sauravrout
2 Replies

5. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

6. Shell Programming and Scripting

Picking values from a file.

Hi, I have a file which contains values in this format. abc cde fgh ijk lmn opq rst uvw The user will pass the required parameter from the command line. My requirement is that script should pick the values passed by the user and the next value in the next line. Like if the user... (10 Replies)
Discussion started by: arijitsaha
10 Replies

7. Shell Programming and Scripting

Picking contents value of file at run time based on variable values

HI, I have to write a unix script and need your help. in my application where I have to invoke this script a varialble is there where the value comes in a variable . for example variable can be var=ABC like this there will be any type of value in the vcariable. there is a unix directory... (2 Replies)
Discussion started by: manish8484
2 Replies

8. Shell Programming and Scripting

Retrieving values from the oracle table

Hi, How to retrieve two different date values(min & max) from the oracle table and assign to two different variables in the shell script to process further. With Regards (8 Replies)
Discussion started by: milink
8 Replies

9. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

10. Shell Programming and Scripting

Inserting Values From A File Into A Table

Guys, I want to insert some values from a log file into a temporary table. the values in the log file looks like this SV_NAME CC_NAME CP_DISP_RUN_STATE ------- ------------------- ----------------- sble01 ALLTEL WorkMon24Hrs Running I want to enter the... (2 Replies)
Discussion started by: ragha81
2 Replies
Login or Register to Ask a Question