Awk script to run a sql and print the output to an output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk script to run a sql and print the output to an output file
# 1  
Old 06-09-2012
Awk script to run a sql and print the output to an output file

Hi All,

I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file.

Can you anyone pls let me know how do I do it and execute the awk script? Thanks.
# 2  
Old 06-09-2012
Why would you want to run it via awk? That sounds harder than it needs be. You can use the system() function to run your external sql call.
# 3  
Old 06-09-2012
Other than awk, how do I execute all these SQL's and have the output printed in a txt file?
# 4  
Old 06-10-2012
A basic shell script should do..use sqlplus and spool the output to a file...
# 5  
Old 06-10-2012
Try to include all of your scripts into on unix shell as this example:
Quote:
echo "select * from mytable where number = '20348234'" | mydbname mydbusername > outputfile.txt
don't forget to chmod the shell file with 775
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run sql query in shell script and output data save as delimited text

I want to run sql query in shell script and output data save as delimited text (delimited text would be comma) Code: SPOOL_FILE=/pgedw/dan.txt SQL=/pgedw/dan.sql sqlplus -s username/password@myhost:port/servicename <<EOF set head on set COLSEP , set linesize 32767 SET TRIMSPOOL ON SET... (8 Replies)
Discussion started by: Jaganjag
8 Replies

2. Shell Programming and Scripting

awk to print field from lookup file in output

The below awk uses $3 and $4 in search as the min and max, then takes each $2 value in lookup and compares it. If the value in lookupfalls within the range in searchthen it prints the entire line in lookup/ICODE]. What I can't seem to figure out is how to print the matching $5 from search on that... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

awk script to search output for a value and print

GOODNUMBERS="1 2 3 4 5 6 3 3 34 34 5 66 12" BADNUMBERS="7 3 12 5 66" for eachnum in `echo ${GOODNUMBERS}` do echo ${BADNUMBERS} | gawk -v threshold=${eachnum} '$1 != threshold' done what im trying to do with the above is, i want to print numbers that are in the GOODNUMBERS... (10 Replies)
Discussion started by: SkySmart
10 Replies

4. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

5. Shell Programming and Scripting

awk command : To print the output to a file

half of the problem is already solved with the help of bartus11 suggestion I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. 50.000000 1 1 1 1000.00000 1000.00000 ... (5 Replies)
Discussion started by: shashi792
5 Replies

6. Shell Programming and Scripting

SQL Script's output to a CSV file

I need to call and execute an SQL script within a KSH script and get the output/extracted data into a CSV file. Is there any way to get the out put in a CSV file other than spooling ? I tried spooling. Problem is if there is any wrning/comment/Error they all will be spooled into the csv file. I... (4 Replies)
Discussion started by: Sriranga
4 Replies

7. Shell Programming and Scripting

To parse through the file and print output using awk or sed script

suppose if u have a file like that Hen ABCCSGSGSGJJJJK 15 Cock ABCCSGGGSGIJJJL 15 * * * * * * : * * * . * * * : Hen CFCDFCSDFCDERTF 30 Cock CHCDFCSDHCDEGFI 30 * . * * * * * * * : * * :* : : . The output shud be where there is : and . It shud... (4 Replies)
Discussion started by: cdfd123
4 Replies

8. Shell Programming and Scripting

Run SQL queries in DB2 and output to file

Hi, I new to Unix and scripting. Following is my requirement. Can someone tell me whether its possible or not. Also please let me know how to proceed further if this is possible. List of queries are stored in a file. For example, I have to run a query like this: Select * from &XYZ where... (0 Replies)
Discussion started by: simhasuri
0 Replies

9. UNIX for Dummies Questions & Answers

using awk or sed to print output from one file

dear i have one file regarding >abshabja>sdksjbs>sknakna>snajxcls so i want to be output like >abshabja >sjkabjb >sknakna >snajxcls Any using awk or sed will help thanks (2 Replies)
Discussion started by: cdfd123
2 Replies

10. Shell Programming and Scripting

any possible to run sql result and output to file

Hi, I search all post...and no soluation about..if i would like to run a sql statement and output the result to txt file. for example, i usually run "sql" to logon the database and run select statement. Then I need to copy the output into the result.txt. Can I run the script to do this... (7 Replies)
Discussion started by: happyv
7 Replies
Login or Register to Ask a Question