Sponsored Content
Top Forums Shell Programming and Scripting Perl Programming for Splitting Post 302303537 by sagarbsa on Friday 3rd of April 2009 12:15:52 AM
Old 04-03-2009
# Program to get the Query, Parse count, Execute count, Fetch count, Total cpu time and Total elapsed time.

# Begin Prompt for User Input .. Input Trace File

$inputFile = &promptUser("\n\t\t Enter the TraceFile Name");


#Open input and output files and create File Handles

open(INFILE,"<$inputFile") or die " Input File opening ERROR :: $!";
$opFile = $inputFile.".xls";
open(OUTFILE,">$opFile") or die " Output File opening ERROR :: $!";

# Write the Headings to the file
print OUTFILE "SQL Query and the Indexes used in the Query is printed in the output_log file \n\n";
#print OUTFILE "===================================================================\n";
#print OUTFILE "SQL QUERY ~PARSE Count ~EXECUTE Count ~FETCH Count ~TOTAL CPU TIME ~TOTAL ELAPSED TIME ~FullTableScan\n";
# initializations

$SQLLINE="";
$CUTLINE="";
$CUTLINE1="";
$FLAG=0;
$SUFLAG=0;
$Indexflag=0;
$MyFlag=0;
$Rows=0;
$Blocks=0;
$Result=0;
$Zero=0;
$Level=10;
#
# Working on the input file One Line at a Time !!! Read from given I/P file Line by Line.
foreach $actual_line (<INFILE>)
{
# To get the PLAN !!!

# if line is a sql statement change the flag status
# and copy the line to a variable


if( $actual_line =~ m/^SELECT/ || $actual_line =~ m/^select/ || $actual_line =~ m/^update/ || $actual_line =~ m/^UPDATE/) {
$FLAG=1;
$SUFLAG=1;
#print OUTFILE "------------------------------------------------------------------------------- \n\n";
chomp($actual_line);
$SQLLINE=$actual_line;
}

#change the flag status when complete sql statement is read

elsif($actual_line =~ m/^call/){
#print "call";
$FLAG=0;
print OUTFILE "***************************************************************************** \n";
print OUTFILE "$SQLLINE" ;
$CUTLINE=$SQLLINE;
@charArray = split(/FROM/,$CUTLINE);
$CUTLINE1=@charArray[1];
print OUTFILE "$CUTLINE1" ;

$SQLLINE="";
next;
}

# read the complete sql statement line by line and join them together

elsif($FLAG==1) {
chomp($actual_line);
$line=$actual_line;
$temp=$SQLLINE;
$SQLLINE=$temp.$line;
next;
}
# Above code Completes the program for copying the SQL Query.


else{
next;
}



}


##
# Close all file handles !!!
##
close(INFILE) or die " INFILE CLOSING ERROR : $!";
close(OUTFILE) or die " OUTFILE CLOSING ERROR : $!";

#
# Display Console message to user ..

print "\t\tOUTPUT printed to File : $opFile \n";



# Prompting the usr to enter an Input file or accept a default I/P File ...
#
#

sub promptUser
{

local($promptString,$defaultValue) = @_;

if ($defaultValue)
{
print $promptString, "[", $defaultValue, "]: ";
}
else
{
print $promptString, ": ";
}

$| = 1; # force a flush after our print
$_ = <STDIN>; # get the input from STDIN (presumably the keyboard)

chomp;

if ("$defaultValue")
{
return $_ ? $_ : $defaultValue; # return $_ if it has a value
}
else
{
return $_;
}
}



This is the code that I have created. The problem comes as it is splitting for FROM but it is not splitting for from.
Also need to continue with the logic
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

splitting on dot in perl

I am trying to split input that looks like ,2005-09-12 01:45:00.000000,2005-09-12 01:48:18.000000, I want to split on the dot . What I am using is ($ev_time,$rol)=split(/\./),$inputfile; This does not recognize the dot as what I want to split on. (2 Replies)
Discussion started by: reggiej
2 Replies

2. UNIX for Dummies Questions & Answers

PERL - DB programming

Hi friends, What are the possible ways to connect to DB2 database from Perl (on unix). I need to connect to DB2 and get records for further processing. Can you please suggest the best possible way. I heard about DBI/DBD, if you have some sample scripts please post them too. Thanks in advance. (3 Replies)
Discussion started by: satguyz
3 Replies

3. Shell Programming and Scripting

Perl - Need help on splitting string

Let's say I have a very long string with no spaces but just words stored in $very_long_string. $very_long_string = "aaaaaaaaaaabbbbbbbbbbbccccccccccccdddddddddddd"; I can do this to split the string into 1 character each and store them in an array: @myArray = split(//, $very_long_string); ... (3 Replies)
Discussion started by: teiji
3 Replies

4. Shell Programming and Scripting

PERL need help splitting argument

If i have a script name.pl I run it like name.pl -v file.txt -t ext2 -u user -j how can I edit the array @ARGV so when my script calls $ARGV = -v file.txt $ARGV = -j (2 Replies)
Discussion started by: 3junior
2 Replies

5. Shell Programming and Scripting

perl, splitting out specific parts of the string

Hi there, I have an output from a command like this # ypcat -k netgroup.byuser| grep steven steven.* users_main,users_sysadmin,users_global,users_backup_team and wanted to pull the 'users' netgroups returned into a perl array, that will look like this users_main... (2 Replies)
Discussion started by: rethink
2 Replies

6. Shell Programming and Scripting

perl programming

how to link the linux files in perl on the local webpage ???? suppose we have some results and want to get them published on the local webpage of our internal site. how this can be done using HTML and perl together , so that the results are published directly on the webpage. thanks kullu (0 Replies)
Discussion started by: kullu
0 Replies

7. Shell Programming and Scripting

Splitting a file into several smaller files using perl

Hi, I'm trying to split a large file into several smaller files the script will have two input arguments argument1=filename and argument2=no of files to be split. In my large input file I have a header followed by 100009 records The first line is a header; I want this header in all my... (9 Replies)
Discussion started by: ramky79
9 Replies

8. Shell Programming and Scripting

Perl programming help

I am trying to make a simple perl program that reads 20 characters upstream from the codon ATG in a given sequence. The following is what I have. I just dont know how to make the program read 20 characters upstream from the ATG codon. print "\nThis program will read 20 characters upstream... (1 Reply)
Discussion started by: patiencenpray
1 Replies

9. Shell Programming and Scripting

perl : splitting the data into 2 different variables

I have a perl variable which contains the below value. $var1 = "2% / 51%" Now I would like to split the data into 2 different variables. For example $part1 = 2 $part2 = 51 Could anyone please help me in this regard ? Regards, GS (4 Replies)
Discussion started by: giridhar276
4 Replies

10. Shell Programming and Scripting

Splitting a file and creating new files using Perl script

Hi All, I am new to Scripting language. I want to split a file and create several subfiles using Perl script. Example : File format : Sourcename ID Date Nbr SU IMYFDJ 9/17/2012 5552159976555 SU BWZMIG 9/14/2012 1952257857887 AR PEHQDF 11/26/2012 ... (13 Replies)
Discussion started by: Deepak9870
13 Replies
gasp(1) 						       GNU Development Tools							   gasp(1)

NAME
gasp - a preprocessor for assembly programs SYNOPSIS
gasp [-a|--alternate] [-c CHAR | --commentchar CHAR] [-d|--debug] [-h|--help] [-M|--mri] [-o OUTFILE | --output OUTFILE] [-p|--print] [-s|--copysource] [-u|--unreasonable] [-v|--version] INFILE ... DESCRIPTION
The primary purpose of the GNU assembler is to assemble the output of other programs--notably compilers. When you have to hand-code spe- cialized routines in assembly, that means the GNU assembler is an unfriendly processor: it has no directives for macros, conditionals, or many other conveniences that you might expect. In some cases you can simply use the C preprocessor, or a generalized preprocessor like M4; but this can be awkward, since none of these things are designed with assembly in mind. gasp fills this need. It is expressly designed to provide the facilities you need with hand-coded assembly code. Implementing it as a preprocessor, rather than part of the assembler, allows the maximum flexibility: you can use it with hand-coded assembly, without paying a penalty of added complexity in the assembler you use for compiler output. INFILE... are the files to be preprocessed. OPTIONS
The simplest way to use GASP is to run it as a filter and assemble its output. In Unix and its ilk, you can do this, for example: $ gasp prog.asm | as -o prog.o Naturally, there are also a few command-line options to allow you to request variations on this basic theme. Here is the full set of pos- sibilities for the GASP command line. -a --alternate Use alternative macro syntax. *Note Alternate macro syntax: Alternate, for a discussion of how this syntax differs from the default GASP syntax. -c CHAR --commentchar CHAR Use CHAR as the comment character. The default comment character is `!'. For example, to use a semicolon as the comment character, specify `-c ';'' on the GASP command line. Since assembler command characters often have special significance to command shells, it is a good idea to quote or escape CHAR when you specify a comment character. For the sake of simplicity, all examples in this manual use the default comment character `!'. -d --debug Show debugging statistics. In this version of GASP, this option produces statistics about the string buffers that GASP allocates internally. For each defined buffersize S, GASP shows the number of strings N that it allocated, with a line like this: strings size S : N GASP displays these statistics on the standard error stream, when done preprocessing. -h --help Display a summary of the GASP command line options. -M --mri Use MRI compatibility mode. Using this option causes GASP to accept the syntax and pseudo-ops used by the Microtec Research `ASM68K' assembler. -o OUTFILE --output OUTFILE `-o OUTFILE' `--output OUTFILE' Write the output in a file called OUTFILE. If you do not use the `-o' option, GASP writes its out- put on the standard output stream. -p --print Print line numbers. GASP obeys this option _only_ if you also specify `-s' to copy source lines to its output. With `-s -p', GASP displays the line number of each source line copied (immediately after the comment character at the beginning of the line). -s --copysource Copy the source lines to the output file. Use this option to see the effect of each preprocessor line on the GASP output. GASP places a comment character (`!' by default) at the beginning of each source line it copies, so that you can use this option and still assemble the result. -u --unreasonable Bypass "unreasonable expansion" limit. Since you can define GASP macros inside other macro definitions, the preprocessor normally includes a sanity check. If your program requires more than 1,000 nested expansions, GASP normally exits with an error message. Use this option to turn off this check, allowing unlimited nested expansions. -v --version Display the GASP version number. INFILE ... The input file names. You must specify at least one input file; if you specify more, GASP preprocesses them all, concatenating the output in the order you list the INFILE arguments. Mark the end of each input file with the preprocessor command `.END'. SEE ALSO
`gasp' entry in info; The GNU Binary Utilities, Roland H. Pesch (October 1991); gasp(1). Debian September 1999 gasp(1)
All times are GMT -4. The time now is 11:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy