So I have this spool file having this kind of content.
SQL> select file_name from dev_files;
FILE_NAME
------------------------------------------------------------------
file1.txt
file2.doc
file3.pdf
total.xls
4 rows selected.
SQL> spool off
I am writing a ksh script to load these files into a ftp server and update a log file. and I am stuck up bigtime. Here is the portion of my poor code after many tries.
dump="spoolfile.txt"
while read line;
do
if [[`expr match "$line" 'SQL'` !=3]] && [[`expr match "$line" 'FILE_NAME'` !=9]] && [[`expr match "$line" '---------'` !=9]]
then
ftp -inv $tgt_server <<EOT
quote user $uname
quote password $pword
mput $src_path/$line
quit
EOT
echo "sent $line" >> sent_files.log
fi
done < $dump
how do i ensure that “no rows selected” and say “4 rows selected.” are not read? there can be any number instead of 4 corresponding to number of files. In the case of no files the spool file looks like this. the ‘.’ is also missing.
SQL> select file_name from dev_files;
no rows selected
SQL> spool off
I agree with most of the comments about ‘turn off headings’ etc in the SQLPlus,
but this is Easy Peasy 😉
You’ll have to experiment with what values to put in the case statement to clean it up completely.
Also note that for any unusual characters, like ‘>’, it is probably better to include them as a character class
[>](again requiring some experimentation on your part)And finally, note that if you want to include white-space chars in the case match targets, either surround the phrase in dbl-quotes (“) or escape each WS char like ‘\’.