Home » Infrastructure » Unix » Capture a filename from UNIX to insert into a table
Capture a filename from UNIX to insert into a table [message #98032] Tue, 25 November 2003 11:18 Go to next message
Demetrios
Messages: 10
Registered: November 2003
Junior Member
I am trying to figure out how I can capture a filename and insert it into a table in the database. Can anyone help? Right now, I am looking into a PERL book we have in our shop.

Also, does anyone know how you could get a record count from a file before loading it into the database via SQL Loader?

Thanks!
Re: Capture a filename from UNIX to insert into a table [message #98071 is a reply to message #98032] Mon, 19 January 2004 09:40 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Well, you probably have a solution by now but anyway:

Replace each "~" below with a "<" !!

SQL> create table t (filename varchar2(40), lines number);

#!/usr/bin/ksh
INDIR=/dbd01/data/in
F1=my_file.dat

LINES_F1=`wc -l ${INDIR}/${F1} | awk '{ print $1 }'`

sqlplus -s scott/tiger@engdev ~~EOF > log.txt
set pagesize 0 feedback off verify off heading off echo off
insert into t values ('$F1', $LINES_F1);
exit;
EOF

SQL> select * from t;
FILENAME                                      LINES
---------------------------------------- ----------
my_file.txt                                       4
Previous Topic: Simple Shell Script Question
Next Topic: to change contents of a file and save using sed/awk
Goto Forum:
  


Current Time: Fri Mar 29 10:47:09 CDT 2024