![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 06:19 PM |
| Unix shell Script To Send SMS | sdcoms | UNIX for Advanced & Expert Users | 1 | 05-16-2007 12:01 PM |
| Shell script to send email alert for core dump | rtatineni | SUN Solaris | 1 | 08-17-2006 03:33 PM |
| Send e-mail in Shell script | annelisa | Shell Programming and Scripting | 1 | 07-13-2006 08:35 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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. |
|
||||
|
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. |
|
||||
|
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 Code:
sed -e "s/\(INFILE \).*/\1'${YOURVARIABLE}'/" yourcontrolfile.ctl > newcontrolfile.ctl
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|