i am using UTL_FILE
utility in oracle to get the data in to csv file. here i am using the script.
so i am getting the set of text files
case:1
Columns in both case is different. To make it generic I wrote a perl script which will print the rows. It generates the regex from headers and used it to calculate the rows. I assumed that first line always represents the number of columns.
#!/usr/bin/perl -w
open(FH, $ARGV[0]) or die "Failed to open file";
# Get coloms from HEADER and use it to contruct regex
my $head = ;
my @col = split(",", $head); # Colums array
my $col_cnt = scalar(@col); # Colums count
# Read rest of the rows
my $rows;
while() {
$rows .= $_;
}
# Create regex based on number of coloms
# E.g for 3 coloms, regex should be
# ".*?",".*?",".*?"
# this represents anything between " and "
my $i=0;
while($i < $col_cnt) {
$col[$i++] = "\".*?\"";
}
my $regex = join(",", @col);
# /s to treat the data as single line
# /g for global matching
my @row_cnt = $rows =~ m/($regex)/sg;
print "Row count:" . scalar(@row_cnt);
Just store it as row_count.pl
and run it as ./row_count.pl filename