How to send filename as variable in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to send filename as variable in a shell script
# 1  
Old 06-26-2006
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  
Old 06-26-2006
What do you mean by replacing the file.. do you want to copy or rename it..?
# 3  
Old 06-26-2006
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  
Old 06-26-2006
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  
Old 06-26-2006
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  
Old 06-26-2006
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  
Old 06-27-2006
Thank you. It works for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

2. Shell Programming and Scripting

Fetch the latest filename shell script

Hi I want to fetch the latest file form the list example example= filename RATE_STATE_SETUPS.20151222.ccyymmdd.hhmmss.txt File pick which have latest ccyymmdd.hhmmss list of file in directory are RATE_STATE_SETUPS.20151222.20151222.170101.txt... (5 Replies)
Discussion started by: MOHANP12
5 Replies

3. Shell Programming and Scripting

How to sort the timestamp in the filename in shell script?

originally the shellscript #ln_file_name=`echo $ld_interface_date"_"${8}".csv"` #ln_file_name=`echo 201202011527_HL_HLTM1_B04A.csv` ln_file_name="*"`echo ${7}".csv"` get_file_list_1=$log_path"tm1_file_list.gfl1" cd ${source_path} echo "Try to find any file exist in the... (10 Replies)
Discussion started by: feilhk
10 Replies

4. Shell Programming and Scripting

Help shell script to list filename file_path

HI owner date and time and size of file in a row shell script to list filename file_path i have tried the below code present_dir=`pwd` dir=`dirname $0` list=`ls -lrt | awk {'print $9,$3,$6,$7,$8'}` size=`du -h` path=`cd $dir;pwd;` printf "$list" printf "$path" printf " $size" ... (4 Replies)
Discussion started by: abiram
4 Replies

5. Shell Programming and Scripting

Shell script if [[ -L <filename> ]]

Hi Please describe about following condition if ] in shell script. Also please provide the link related all the flags which are applicable for if condition in Shell (4 Replies)
Discussion started by: munna_dude
4 Replies

6. Shell Programming and Scripting

Call a awk script with variable and input filename

HI, MY question is a very simple one: if i want to call an awk script with the input file name and also pass a variable value , then how to do it. #>awk -f my_script.awk -v variable=value my_inputfile.txt I can't do it like this. throws error: awk: my_script.awk:18:... (0 Replies)
Discussion started by: Onkar Banerjee
0 Replies

7. Shell Programming and Scripting

Which shell script will call if i execute sh (without filename)?

Hi Friends, The below shell script is written by third party to create B2k_session_id.iam trying to execute this script.When i execute below script it is calling some other scripts.How to find which scripts is calling? . `execom commfunc.com` echo " $PRESENTATION_MODE " if then echo... (1 Reply)
Discussion started by: vadlamudy
1 Replies

8. UNIX for Dummies Questions & Answers

How to send e-mail from shell script ( C shell )?

Hi , How to send e-mail from shell script ( C shell ) . Mailx command is not working ( It didn't giving error also ). Please help me (2 Replies)
Discussion started by: arukuku
2 Replies

9. Shell Programming and Scripting

Send filename as variable in a shell script

I am having some trouble with a shell script I am writing. In the program I pass the path of where certain file names exist. I then want to loop through each file name and pass it as a DATA variable when calling sqlldr for a control file. This is what I have: ls $FILEPATH/${FILENAME}*.csv ... (4 Replies)
Discussion started by: neva
4 Replies

10. Shell Programming and Scripting

Shell script to use the last modified filename in a variable

Forgive me if this is a trivial question, but I haven't been able to find the answer to this. Basically I've got a list of files in a particular directory that have the general form t_*.dat. (I have other files in the same directory as well). Essentially what I want to do is obtain the name... (1 Reply)
Discussion started by: lost.identity
1 Replies
Login or Register to Ask a Question