0

I'm getting one extra line(not sure how)in the output of the sql query when run through shell script. When checking the count in sql developer the count is correct.

Below is the query which I've run through script:

sqlplus -s user/passwd@DB << EOF > /dev/null 2>&1

set heading off
set feedback off
set verify off
set pagesize 50000
set trimspool on
set wrap off
set linesize 2000

spool /home/sql_test.txt;

select /*+parallel(a,4)*/ substr(dati, 1, 11), substr(dati, 13, 500)
from ferdquatadm.tmp_fq_migration a, account b, customer_node_history c
where substr(dati, 1, 11) = account_name
and b.customer_node_id = c.customer_node_id
and sysdate between effective_start_date and effective_end_date
and schedule_id = 1234;

spool off;

exit
EOF

sed '1d' sql_test.txt > sqltest_1
mv sqltest_1 mig_code_1234.txt
rm -rf sql_test.txt

In sql developer, the count of rows is 53754, whereas in unix the count is 53755:

$ wc -l mig_code_1234.txt
53755 mig_code_1234.txt

Any help is most welcome.

Boneist
  • 22,910
  • 1
  • 25
  • 40
User123
  • 1,498
  • 2
  • 12
  • 26
  • sqlplus is an oracle tool - please tag your post correctly. – SMor Jun 09 '17 at 12:59
  • 1
    Have you checked that the first or last line in the unix file isn't an empty line? If the first line is null, maybe [set newpage none](https://stackoverflow.com/questions/5576901/sqlplus-spooling-how-to-get-rid-of-first-empty-line) may be of use to you. – Boneist Jun 09 '17 at 13:10
  • I've used sed '1d' command to remove the header from my output, anyways, after using set newpage none in the query, I'm getting one line less, i.e. wc -l mig_code_1234.txt 53753 mig_code_1234.txt – User123 Jun 09 '17 at 13:28
  • The required output should be 53754 rows. – User123 Jun 09 '17 at 13:32
  • @Boneist It's working for me, yes the first line was null. Thanks. – User123 Jun 09 '17 at 13:48

0 Answers0