Software Testing Life Cycle
From: sunny.deb, 8 months ago
Software Testing Life Cycle
SlideShare Link
Linux, Solaris, Scripting, Testing, QA, Database, Puzzles ...
Posted by
Vishnu Agrawal
at
9:25 AM
0
comments
I need to read a csv file and insert the data from csv to oracle. I created below perl script which will read the csv file line by line and will create INSERT statement accordingly.
#!/usr/bin/perl
$filename = "test.csv";
open(INFILE, "<", $filename)
or die "Can't open $filename for reading: $!\n";
my(@lines) = <INFILE>;
my($line1) = $lines[0];
my($line2) = $lines[1];
print "$line1 \n";
print "$line2 \n";
close(INFILE);
my($tablename) = "mytable";
my($createquery) = "Create table " . $tablename . "(";
my(@var1) = split("\t", $line1);
my(@var2) = split("\t", $line2);
my($i) = 0;
for $item1 (@var1){
chomp($item1);
$createquery = $createquery . $item1 . " ";
$data = $var2[$i++];
print "$item1\t : $data\n";
if(checkData($data) eq "int"){
$createquery = $createquery . "number(10,0), ";
}
elsif(checkData($data) eq "float"){
$createquery = $createquery . "number(10,2), ";
}
else{
$createquery = $createquery . "varchar2(50), ";
}
}
$createquery = substr($createquery,0, -2);
$createquery = $createquery . ");";
print "$createquery\n";
$i = 0;
for $dataline (@lines){
if ( $i == 0){
$i = 1;
next;
}
chomp($dataline);
my(@dataitem) = split("\t", $dataline);
my($insertquery) = "INSERT INTO " . $tablename . " VALUES (";
print "$dataitem\n";
for $items (@dataitem){
if( (checkData($items) eq "int") || (checkData($items) eq "float") ){
$insertquery = $insertquery . $items .",";
}
else{
$insertquery = $insertquery . "\"" . $items . "\"" .",";
}
}
$insertquery = substr($insertquery, 0, -1);
$insertquery = $insertquery . ")";
print "$insertquery\n";
}
sub checkData(){
if(@_[0] =~ /^-?\d+$/){
return "int";
}
elsif(@_[0] =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/){
return "float";
}
else{
return "string";
}
}
Posted by
Vishnu Agrawal
at
4:34 PM
0
comments
Labels: perl script
I have a csv file and i have to make the CREATE TABLE statement (which later will be used to create an Oracle table) by reading first and second line of the csv file. First line in the csv file is column headers and the second line is actual data. By reading the first line, i will create column name and by reading the second line, i'll decide the data type for the column.
Below is the perl script for the same: (i am assuming that data in the csv file is tab seperated)
#!/usr/bin/perl
$filename = "test.csv";
open(INFILE, "<", $filename) or die "Can't open $filename for reading: $!\n";
@lines = <INFILE>;
$line1 = $lines[0];
$line2 = $lines[1];
print "$line1 \n";
print "$line2 \n";
close(INFILE);
$tablename = "mytable";
$query = "Create table " . $tablename . "(";
@var1 = split("\t", $line1);
@var2 = split("\t", $line2);
$i = 0;
for $item1 (@var1){
chomp($item1);
$query = $query . $item1 . " ";
$data = $var2[$i++];
print "$item1\t : $data\n";
if($data =~ /^-?\d+$/){
$query = $query . "number(10,0), ";
}
elsif ($data =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/){
$query = $query . "number(10,2), ";
}
else{
$query = $query . "varchar2(50), ";
}
}
$query = substr($query,0, -2);
$query = $query . ");";
print "$query\n";
Posted by
Vishnu Agrawal
at
10:36 PM
0
comments
Labels: perl script
I need to read a csv file, and process each and every column data (i do not know the column count before processing the file)
#!/usr/local/bin/perl
if (scalar(@ARGV) < 1)
{
print "Please Specify the file name to be read \n";
exit
}
$file = $ARGV[0];
open FILE, "< $file" or die "Can't open test.csv : $!";
while(<FILE>){
chop;
my(@columns)= split("\t");
my($colnum)=$#columns;
# print "Number of Column in this row is : $colnum\n";
foreach $col(@columns){
print "$col \t";
}
print "\n";
}
close FILE;
Posted by
Vishnu Agrawal
at
6:31 PM
0
comments
Labels: perl script
I need to read a csv file, and process each and every column data (i know the column count before processing the file)
#!/usr/local/bin/perl
open FILE, "< test.csv" or die "Can't open test.csv : $!";
while(){
chomp;
($col1,$col2,$col3,$col4) = split ("\t");
print "$col1 \t";
print "$col2 \t";
print "$col3 \t";
print "$col4 \t";
print "\n";
}
close FILE;
Posted by
Vishnu Agrawal
at
6:27 PM
0
comments
Labels: perl script
I need to pick few lines from a particular file and check the data type of values of a particular column. Following is the perl script for the same:
#!/usr/bin/perl
$filename = "test.csv";
open(INFILE, "<", $filename) or die "Can't open $filename for reading: $!\n";
@lines =<INFILE>;
$line1 = $lines[0];
$line2 = $lines[1];
print "$line1 \n";
print "$line2 \n";
close(INFILE);
@var1 = split("\t", $line2);
for $item (@var1){
if($item =~ /\D/){
print "$item\t : Has Non Digits\n";
}
elsif ($item =~ /^\d+$/){
print "$item\t : Whole Number\n";
}
elsif ($item =~ /^-?\d+$/){
print "$item\t : Integer\n";
}
elsif ($item =~ /^[+-]?\d+$/){
print "$item\t : +/- Integer\n";
}
elsif ($item =~ /^-?\d+\.?\d*$/){
print "$item\t : Real Number\n";
}
elsif ($item =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/){
print "$item\t : Float Number\n";
}
else{
print "$item\t : NAN\n";
}
}
Posted by
Vishnu Agrawal
at
6:23 PM
0
comments
Labels: perl script
Method 1:
#!/usr/bin/perl
$filename = "test.csv";
open(INFILE, "<", $filename)
or die "Can't open $filename for reading: $!\n";
$line_number = 1;
while (
$line = $_;
last if $. == $line_number;
}
if ($. != $line_number) {
die "Didn't find line $line_number in $filename\n";
}
print;
close(INFILE);
Method 2:
#!/usr/bin/perl
$filename = "test.csv";
open(INFILE, "<", $filename)
or die "Can't open $filename for reading: $!\n";
@lines =
$line1 = $lines[0];
$line2 = $lines[1];
print "$line1 \n";
print "$line2 \n";
close(INFILE);
Posted by
Vishnu Agrawal
at
6:19 PM
0
comments
Labels: perl script
If you want the Terminal window title to be set automatically to the remote zone you have logged into, add this to your .bashrc file on the remote machine.
# Terminal settings
PS1="[\u@\h \W]# "
if [ -n "$PS1" ]; then
echo -n -e "\033]0;`hostname`\007"
fi
Posted by
Vishnu Agrawal
at
9:37 PM
0
comments
Labels: solaris
TNSNAMES.ORA is a configuration file that defines databases addresses for establishing connections to the database. It resides in ORACLE HOME\NETWORK\ADMIN directory. Below is the sample entry in TNSNAMES.ORA
<addressname> =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host = <hostname>)(Port = <port>))
)
(CONNECT_DATA =
(SERVICE_NAME = <sid>)
)
)
Posted by
Vishnu Agrawal
at
1:53 PM
0
comments
Labels: oracle
Below is the sample perl script, if you want to read some data from a file and pass it to as a argument in your perl script.
#!/usr/local/bin/perl
open FILE, "testoids" or die $!;
while (
{
chomp $_;
systemCmd("oocheck -id $_");
}
close(FILE);
sub systemCmd {
my($cmd) = @_;
print("$cmd\n");
(system($cmd) == 0) || die ("cmd $cmd failed");
}
Posted by
Vishnu Agrawal
at
4:50 PM
0
comments
Labels: perl script