Help with perl script to output data in table format...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with perl script to output data in table format...
# 1  
Old 06-01-2012
Help with perl script to output data in table format...

Hello,
I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored.
Virtual server name follows the word "virtual" in the begging of the line.
There could be multiple profiles assigned to one virtual server.

For example, a file that look like this:
---------------------------
Code:
monitor Test-ICMP4 {
   defaults from icmp
   dest 10.2.34.81
   transparent
virtual VS-Bridge1 {
   snatpool SNAT-IP-Banorte
   pool Bridge1-pool
   destination 10.2.33.102:vpad
   ip protocol tcp
   rules iRule-Bridge1-Logging
   profiles {
      Bridge1_SSL_Profile {
         serverside
      }
      fastl4 {}
   }
   vlans {
      External-VLAN
      PlanetSwitch-VLAN
   } enable
}

virtual VS-Bridge_test {
   destination 10.2.33.59:https
   ip protocol tcp
   rules {
      iRule-testLogging
   }
   profiles {
      SECURE2_SSL_Profile {
         clientside
      }
      http {}
      stream {}
      tcp {}
   }
   vlans {
      External-VLAN
      Internal-VLAN
   } enable


--------------------------------------
the output should look like this:

Code:
Virtual Server          Profiles
VS-Bridge1             Bridge1_SSL_Profile, fastl4
VS-Bridge_test       SECURE2_SSL_Profile, http, stream, tcp

I appreciate your help.
ThanksSmilie

Last edited by Corona688; 06-01-2012 at 03:39 PM..
# 2  
Old 06-01-2012
Code:
$ cat virt2.awk

(STACK[DEP]=="profiles") && ($NF != "}") {      X=X "," $1      }

$NF == "{" {
        INROW=0;
        STACK[++DEP]=$1
        if(NF>2)        PARAM[$1]=$2
        next
}

{
        for(N=1; N<=NF; N++)
        if($N == "}")
        {
                DEP--
                INROW++
        }

        if((INROW == 2)&&(DEP==2))
        {
                print PARAM["virtual"], substr(X,2);
                X=""
        }
}
$ awk -f virt2.awk data

VS-Bridge1 Bridge1_SSL_Profile,fastl4
VS-Bridge_test SECURE2_SSL_Profile,http,stream,tcp

$

# 3  
Old 06-01-2012
Code:
#!/usr/bin/perl

use strict;
my $prof;
$/="\n\n";
print "Virtual Server          Profiles \n";

while (<DATA>) {
if (/virtual\s+(.*?)\s*\{(.*?)profiles\s*\{(.*?)\s*\{(.*?)\}(.*)\}(.*)vlans/sg) {
        my $ser=$1;
        $prof=$3;
        chomp $prof;
        my $str=$5;
        $prof=~s/^\s+//g;       $prof=~s/\s+$//g;
        $str=~s/^\s+//g;        $str=~s/\s+$//g;
        $str=~s/[\{\}]//g;      $str=~s/\n/,/g; $str=~s/,\s+/,/g;
        print $ser,"\t\t",$prof,",",$str,"\n";
        }
}

__DATA__
monitor Test-ICMP4 {
   defaults from icmp
   dest 10.2.34.81
   transparent
virtual VS-Bridge1 {
   snatpool SNAT-IP-Banorte
   pool Bridge1-pool
   destination 10.2.33.102:vpad
   ip protocol tcp
   rules iRule-Bridge1-Logging
   profiles {
      Bridge1_SSL_Profile {
         serverside
      }
      fastl4 {}
   }
   vlans {
      External-VLAN
      PlanetSwitch-VLAN
   } enable
}

virtual VS-Bridge_test {
   destination 10.2.33.59:https
   ip protocol tcp
   rules {
      iRule-testLogging
   }
   profiles {
      SECURE2_SSL_Profile {
         clientside
      }
      http {}
      stream {}
      tcp {}
   }
   vlans {
      External-VLAN
      Internal-VLAN
   } enable

OR
Code:
#!/usr/bin/perl

use strict;
my $prof;
$/="virtual";
print "Virtual Server          Profiles \n";

while (<DATA>) {
if (/(.*?)\s*\{(.*?)profiles\s*\{(.*?)\s*\{(.*?)\}(.*)\}(.*)vlans/sg) {
        my $ser=$1;
        $prof=$3;
        chomp $prof;
        my $str=$5;
        $prof=~s/^\s+//g;       $prof=~s/\s+$//g;
        $str=~s/^\s+//g;        $str=~s/\s+$//g;
        $str=~s/[\{\}]//g;      $str=~s/\n/,/g; $str=~s/,\s+/,/g;
        print $ser,"\t\t",$prof,",",$str,"\n";
        }
}

# 4  
Old 06-04-2012
Thanks

Thanks all
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell output format like table

Hi, OS: Redhat 7.5 shell: Bash Wrote below script to login into oracle via shell script and trying to reset locked account..It works as expected. But I need specific output << EOF should go to target terminal not all out put running below script from ansible command line.. #!/bin/bash... (1 Reply)
Discussion started by: onenessboy
1 Replies

2. Shell Programming and Scripting

Arranging the command output into an html table format

Hi, I need to format a command output for the beolow command: runmqckm -cert -list -db $MQ_KDB -pw $PASSWD -expiry $EXP | grep -v "Certificates in database" The output will be: "ABC - cert name" From: Tuesday, May 25, 1999 11:09:40 AM CDT To: Saturday, May 25, 2019 11:39:40 AM CDT ... (3 Replies)
Discussion started by: bdpl
3 Replies

3. Shell Programming and Scripting

Need the output in the mentioned Table format

Hi Friends, I have the script output like below: Script Output: ----------------------------------------------------------------------- Details of the Client: ----------------------- name: server1; save set: All; ... (3 Replies)
Discussion started by: akmani
3 Replies

4. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

5. Shell Programming and Scripting

Perl -- Script to re-format data

Hi, I have a file with data in the following format BOX -1.000000 -1.000000 0.000000 30.00000 14.00000 0.1000000 0.000000 0.000000 0.000000 0.000000 0.000000 CYLINDER 3.595000 2.995000 0.000000 0.5100000 2.000000 Z 0.000000 0.000000 0.000000 I want to convert these files... (1 Reply)
Discussion started by: lost.identity
1 Replies

6. Shell Programming and Scripting

Output in table format

I have one script which generate file called report.txt having following output parameter_name status comment banking ok NA finance 30% hike NA Loan_department ok 20% HR_Group defaulters Ajay I wanted to convert this file into tabular form. You can see each line contain 3 words and... (7 Replies)
Discussion started by: Nakul_sh
7 Replies

7. Shell Programming and Scripting

Represent the data in table format as in mail content

hi all, I want to Represent the data in table format in mail content sample data should be like this...but i m trying to send this table to mail using unix command...hw do i do????even i echoed the table contents ...doesnt work.... help me <table style="background-color:lightblue;">... (8 Replies)
Discussion started by: navsan
8 Replies

8. Shell Programming and Scripting

convert the output in table format

Hi All, I have a output like below values val1=test.com val2=10.26.208.11 val3=en1 val4=test-priv1.com val5=192.168.3.4 val6=en2 val7=test-priv2.com val8=192.168.4.4 val9=en3 val10=test-vip.com val11=10.26.208.9 val12=$val3 I want to convet this output values into below... (1 Reply)
Discussion started by: kamauv234
1 Replies

9. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

10. Shell Programming and Scripting

how to print out data from mysql table in perl script

I'm having trouble with this code. if i do .\read.pl -u user it prints out 2010-12-20 12:00:00 host1 <cmd>a 2010-12-20 12:00:01 host1 <cmd> <execute> 2010-12-20 12:00:02 host1 <cmd>b 2010-12-20 12:00:03 host1 <cmd>c however, if i enter .\read.pl -h host1 it should... (3 Replies)
Discussion started by: kpddong
3 Replies
Login or Register to Ask a Question