sql - line count with in the text files having multiple lines and single lines -



sql - line count with in the text files having multiple lines and single lines -

i using utl_file utility in oracle info in csv file. here using script.

so getting set of text files

case:1

sample of output in test1.csv file is

"sno","name" "1","hari in singapore ramesh in usa" "2","pong in chaina chang in malaysia vilet in uk"

now counting number of records in test1.csv using linux commans as

egrep -c "^\"[0-9]" test1.csv

here getting record count as

2 (according linux)

but if calculate number of records using select * test;

count(*) ---------- (according info base) 2

case:2

sample of output in test2.csv file is

"sno","name","p" "","","" "","","ramesh in usa" "","",""

now counting number of records in test2.csv using linux commans as

egrep -c "^\"[0-9]" test2.csv

here getting record count as

0 (according linux)

but if calculate number of records using select * test;

count(*) ---------- (according info base) 2

can body help me how count exact lines in case:1 , case:2 using single command

thanks in advance.

columns in both case different. create generic wrote perl script print rows. generates regex headers , used calculate rows. assumed first line represents number of columns.

#!/usr/bin/perl -w open(fh, $argv[0]) or die "failed open file"; # coloms header , utilize contruct regex $head = <fh>; @col = split(",", $head); # colums array $col_cnt = scalar(@col); # colums count # read rest of rows $rows; while(<fh>) { $rows .= $_; } # create regex based on number of coloms # e.g 3 coloms, regex should # ".*?",".*?",".*?" # represents between " , " $i=0; while($i < $col_cnt) { $col[$i++] = "\".*?\""; } $regex = join(",", @col); # /s treat info single line # /g global matching @row_cnt = $rows =~ m/($regex)/sg; print "row count:" . scalar(@row_cnt);

just store row_count.pl , run ./row_count.pl filename

sql linux

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -