Wednesday, 21 May 2014

Pattern Extraction + perl

Extracting last row from certain pattern in a file , that should be arranged , four in a row

19052014_1559 Java_Version Sun Microsystems Inc. 1.4.2_11
19052014_1559 HeapSizeMax 1580793856
19052014_1559 HeapFreeCurrent 1367237048
19052014_1559 HeapSizeCurrent 1580793856
19052014_1559 HeapFreePercent 86.0
19052014_1607 Java_Version Sun Microsystems Inc. 1.4.2_11
19052014_1607 HeapSizeMax 1580793856
19052014_1607 HeapFreeCurrent 1357926040
19052014_1607 HeapSizeCurrent 1580793856
19052014_1607 HeapFreePercent 85.0
19052014_1615 Java_Version Sun Microsystems Inc. 1.4.2_11
19052014_1615 HeapSizeMax 1580793856
19052014_1615 HeapFreeCurrent 1352909344
19052014_1615 HeapSizeCurrent 1580793856

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

Output:

1580793856, 1367237048, 1580793856, 86.0

----------------------
1580793856, 1357926040, 1580793856, 85.0

----------------------
1580793856, 1352909344, 1580793856, 85.0
 


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

open("FILE","kishtry");
$y=0;
while($line=<FILE>)
{
     if($line =~ /Java_Version/)
         {
         $x=0;
        }
    else
        {
         $x=1;
        }

    @s=split(/ /,$line);

    if ($x == 1)
    {
        if($y < 3 )
        {
        chomp($s[@s-1]);
        print "$s[@s-1], ";
        $y=$y+1;
        }
        else
        {
        print "$s[@s-1]\n";
        $y=0;
                print "----------------------\n";
        }
    }
}

    close(FILE);
                
---------------------------------------------------------------------------------------------------------------------------------------




Friday, 16 May 2014

Extracting pattern + from results + perl

Extract Pattern:

MPDE2
./lost+found/sun10_x86.x.70824b20ac1c11de94390002c45ed04c@@/main/0
MPDE2
./bscs/batch/config/README.mpde2@@/main/1
./bscs/batch/config/install.sh@@/main/1
./bscs/batch/config/make.aix4@@/main/1
BATCH
./bscs/batch/bscs.passwd@@/main/1
./bscs/batch/install.txt@@/main/1
./bscs/batch/readme@@/main/1
BATCH
./bscs/batch/build.xml@@/main/1
./bscs/batch/src/bchs/ChargeItem.cpp@@/main/10
./bscs/batch/src/bchs/ChargeItem.hpp@@/main/4
./bscs/batch/src/bchs/DocHeader.cpp@@/main/15
./bscs/batch/src/bchs/DocHeader.hpp@@/main/3
./bscs/batch/src/bchs/UdrLocalDefines.hpp@@/main/2
./bscs/batch/src/bghs/UdrParser.cpp@@/main/10
./bscs/batch/src/bghs/UdrParser.hpp@@/main/7
BATCH
./blueprint/performance/perfclient/input/activateContract.xml@@/main/1
./blueprint/performance/perfclient/input/activateCustomer.xml@@/main/1
./blueprint/performance/perfclient/input/activatePrepaid.xml@@/main/1
./blueprint/performance/perfclient/input/billcycles.txt@@/main/1



Script:


use warnings;
$comp=uc($ARGV[0]);

open("FILE","output2.txt");
@line=<FILE>;
$d=0;
$e=0;
for($i=0;$i<@line;$i++)
{
        chomp($line[$i]);
        if($line[$i]=~/^$comp/)
        {
        $d=$d+1;
        $e=1;
        }
        if($d == 1)
        {
        print $line[$i]."\n";
        }
        $d=0 if($d > 1);
        exit if(($e == 1)&&($line[$i] !~ /^$comp/)&&($line[$i] =~ /^[A-Z]+/));
}