Shell script to perform appending of .sql files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to perform appending of .sql files
# 1  
Old 06-20-2013
Shell script to perform appending of .sql files

Hi, We are having multiple .sql files generated programatically which is not containing..
Code:
create or replace

-- at the start
and
Code:
/

-- at the end

We need to append those .sql files with the above 2 statements at their respective positions.

We will be really thankful to get responses regarding shell script to perform the same.
# 2  
Old 06-20-2013
Do you need it on all the lines of the *.sql or only at the start and end of the file ?
For all the lines, here is the solution
Code:
sed -e 's/^/create /g' -e 's/$/ \//g' file  > new-file

This User Gave Thanks to rajamadhavan For This Post:
# 3  
Old 06-20-2013
Try below.

Code:
 
for file in *.sql ; do
awk 'BEGIN{printf "create or replace "}{print $0}END{print "/"}' $file > temp
mv temp $file
done

This User Gave Thanks to vidyadhar85 For This Post:
# 4  
Old 06-20-2013
make sure you support your local charities ...
Code:
echo "create or replace" > /tmp/sqlfile
cat yourfile.sql >> /tmp/sqlfile
echo "/" >> /tmp/sqlfile
mv /tmp/sqlfile yourfile.sql

This User Gave Thanks to Just Ice For This Post:
# 5  
Old 06-20-2013
You could use a grouping command form:
Code:
for file in *.sql
do
        {
                echo "create or replace"
                cat "$file"
                echo "/"
        } # > tmp
        # mv tmp "$file"
done

Remove the hash sign # if the output looks good to redirect the output to tmp file and rename it back to original.
This User Gave Thanks to Yoda For This Post:
# 6  
Old 06-20-2013
Thank you so much for all your help I really appreciate it.
# 7  
Old 06-20-2013
Thank you for helping out
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to execute 10 sql files from a folder through sqlplus in shell script?

I am new to shell scripting and i want to know how to execute the *.sql files from a folder through sqlplus in shell script and files should be execute in sequentially one by one while execution if any ORA error it has to exit from sqlplus session 1) scripts from external folder 2) logs has... (1 Reply)
Discussion started by: sreekanth Reddy
1 Replies

2. Shell Programming and Scripting

Shell script appending output of sql query

I am writing the following script to create the file v_out.txt. sqlplus -s /nolog << EOF CONNECT scott/tiger@orcl; whenever sqlerror exit sql.sqlcode; set newpage 0; SET PAGESIZE 0; SET ECHO OFF; SET FEEDBACK OFF; SET HEADING OFF; SET VERIFY OFF; SET LINESIZE 100; set tab off; set... (7 Replies)
Discussion started by: itzkashi
7 Replies

3. Shell Programming and Scripting

Oop to copy and rename files through SQL Statement in shell Script

#!/bin/sh sqlplus -s "/ as sysdba" << EOF SET HEADING OFF SET FEEDBACK OFF Select pt.user_concurrent_program_name , OUTFILE_NAME FROm apps.fnd_concurrent_programs_tl pt, apps.fnd_concurrent_requests f where pt.concurrent_program_id = f.concurrent_program_id and pt.application_id =... (1 Reply)
Discussion started by: usman_oracle
1 Replies

4. Shell Programming and Scripting

How to perform floating division in shell script?

I want to perform the below division operation in shell script and round the value. val1=6000 val2=5000 res=val1/val2 ----> 1.2---> Round to 2 Please help. (3 Replies)
Discussion started by: vel4ever
3 Replies

5. UNIX for Dummies Questions & Answers

How to perform string replace in shell script?

I have value like ABCDEF,BBCCDD in a shell variable, now i would like to have ABQWEF,BBQWDD in the same shell variable. How can i replace the char at position 3&4 with QW in shell script? (3 Replies)
Discussion started by: vel4ever
3 Replies

6. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

HI all, I want to script where all the server names will be in a text file like server1 server2 server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Discussion started by: joseph.dmello
0 Replies

7. Shell Programming and Scripting

Appending columns of two files using shell script

Hi, I am using ksh, I want to read one csv file and append the columns of another file with new column. My input file: col1,col2 --------- siri,886 satya,890 priya,850 Another file with the below date:(test.csv) col3 ----- 321 333 442 (1 Reply)
Discussion started by: siri_886
1 Replies

8. Shell Programming and Scripting

shell script to run .sql files

hi Friends, Please help me in writing shell script to run list of sql files. database is Oracle 9i, unix os is solaris Requirement is 1. sql file must take two inputs a)feed id and b)business date 2.shell script must out put .xls or .csvfile as out put without trimming any column name and... (1 Reply)
Discussion started by: balireddy_77
1 Replies

9. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: dba_nh
1 Replies

10. Shell Programming and Scripting

Executing Multiple .SQL Files from Single Shell Script file

Hi, Please help me out. I have around 700 sql files to execute in a defined order, how can i do it from shell script (3 Replies)
Discussion started by: anushilrai
3 Replies
Login or Register to Ask a Question