The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-15-2008
dba_nh dba_nh is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 1
Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it.
Requirement: files are ftp to directory. Shell loops through the files and then using a master control file change the infile, badfile parameters with the file name. SQL load file.

I currently have been trying the following.
<<filename>> is what I am using to change in the ctl file.

export MY_DIR=/volume/files

for a in $MY_DIR/*ctl
do
sed -e "s/<<filename>>/$a/g" $a $a.ctl
done

I am wondering if their is a way to reference the infile, badfile directly in the ctl file instead. I also have an insert into a table where the filename that I am loading needs to be inserted. My method leaves me with a badfile with "name.ctl.bad" instead of just "name.bad". I am new to shell scripting so please be nice.

Thanks in advance.