The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need help in finding a string and to send an email using shell script ranga27 Shell Programming and Scripting 10 02-19-2008 05:54 PM
How to write a shell script to send an email to an id madhumathikv Shell Programming and Scripting 4 10-23-2007 05:19 PM
Unix shell Script To Send SMS sdcoms UNIX for Advanced & Expert Users 1 05-16-2007 11:01 AM
Shell script to send email alert for core dump rtatineni SUN Solaris 1 08-17-2006 02:33 PM
Send e-mail in Shell script annelisa Shell Programming and Scripting 1 07-13-2006 07:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-26-2006
gthokala9 gthokala9 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 5
How to send filename as variable in a shell script

Can we can pass the filename as variable in the shell script.
Sending the filename as a parameter file, the shell script takes the filename, needs to replace the string containing the filename with the variable in the shell script.

EX: test1.sh is the shell script and takes file1.csv as parameter file. Then file1.csv has to be replaced in the test1.ctl file where the control file contains the infile option taking as test1.csv

From the command line execute
test1.sh file1.csv

#Take the file1.csv file and replace it in test1.ctl

#test1.ctl
load data
infile 'testing.csv'
......
......

Here the testing.csv has to be replaced by 'test1.csv' in the test1.ctl file. Hope the scenario is clear and any solution is greatly appreciated. Thanks.
  #2 (permalink)  
Old 06-26-2006
Ambikesh Ambikesh is offline
Registered User
  
 

Join Date: Feb 2006
Location: California
Posts: 45
What do you mean by replacing the file.. do you want to copy or rename it..?
  #3 (permalink)  
Old 06-26-2006
gthokala9 gthokala9 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 5
I receive different files with different filenames daily. These files needs to be loaded using sqlldr utility.
The filename in the control file is set to 'testing.csv'. Instead of changing the control file everyday, I am trying to set the filename as variable through a shell script and pass that filename as variable to replace the string in control file from testing.csv to the variable which is nothing but the filename.
  #4 (permalink)  
Old 06-26-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
so you simply want to do something like this:
Code:
my_new_file=todays_file.csv
sqlldr file=${my_new_file} control=comma_sep.ctl
Correct?
  #5 (permalink)  
Old 06-26-2006
gthokala9 gthokala9 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 5
Actually the control file contains the file information as shown. The control file needs to be modified.

#test1.ctl
load data
infile 'testing.csv'
............



In the above test1.ctl, we need to replace testing.csv to the filename that we pass as a parameter from the shell script.
  #6 (permalink)  
Old 06-26-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Why? The sqlldr "data=" command line parameter overrides the INFILE parameter. Also, you can simply remove it from the file altogether using vi.

But if you are really want to do it the way that you described, you can use sed.

Code:
sed -e "s/\(INFILE \).*/\1'newfile.csv'/" yourcontrolfile.ctl > newcontrolfile.ctl
or more specifically:
Code:
sed -e "s/\(INFILE \).*/\1'${YOURVARIABLE}'/" yourcontrolfile.ctl > newcontrolfile.ctl
  #7 (permalink)  
Old 06-27-2006
gthokala9 gthokala9 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 5
Thank you. It works for me.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0