Sponsored Content
Top Forums Shell Programming and Scripting create a shell script that calls another script and and an awk script Post 302209129 by magikminox on Thursday 26th of June 2008 02:50:12 AM
Old 06-26-2008
create a shell script that calls another script and and an awk script

Hi guys

I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file.

#!/bin/sh
echo " $2 $3 $4 $5 $6 $7
isql -w400 -U$2 -S$5 -P$3 << xxx
use $4
go
print"**Changes to the table ************"
select *
from cashflow
where label = 'DEALS'
go
xxx
i also have an AWK script that takes the output produced by the script above and generates a csv file from it and sends the output to another file as CSV.
BEGIN {
count=0;
}

/^[^(]/ {
count+=1
if ( count >1 ){
for (i=1; i <= NF; i = i + 1)
printf("%s,",$i);
printf("\n");
}
}

My problem is.
1.how do i call the first script from another shell script passing in the required parameters.
2.how ho i call the AWK script after the output from above to process the file and produce a csv file.this has to be in the same script as the above.
3.my main problem is how to do the above from ONE shell script.
4.some of date being prcessed by the AWK script is in datetime format.the AWK script is seperating the day,month and year with comma.How do i make it treat 23-06-2008 as single field and not as seperate fields.

Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

2. Shell Programming and Scripting

To Create shell script files from a shell script

Dear Unix and Linux users, Good evening to all. I'm new to this community and thank you for having an wonderful forum. Dear members i had to create almost some 300 shell script files for a particular task. I tried something like this.... #!usr/bin/sh fname=epdb_jobs for x in `cat $fname`... (3 Replies)
Discussion started by: NehaB
3 Replies

3. Shell Programming and Scripting

want to pass parameters to awk script from shell script

Hello, I have this awk script that I want to execute by passing parameters through a shell script. I'm a little confused. This awk script removes duplicates from an input file. Ok, so I have a .sh file called rem_dups.sh #!/usr/bin/sh... (4 Replies)
Discussion started by: script_op2a
4 Replies

4. Shell Programming and Scripting

Call shell script function from awk script

hi everyone i am trying to do this bash> cat abc.sh deepak() { echo Deepak } deepak bash>./abc.sh Deepak so it is giving me write simply i created a func and it worked now i modified it like this way bash> cat abc.sh (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

5. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

6. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

7. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

8. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

9. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

10. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies
DB2_FETCH_ROW(3)							 1							  DB2_FETCH_ROW(3)

db2_fetch_row - Sets the result set pointer to the next row or requested row

SYNOPSIS
bool db2_fetch_row (resource $stmt, [int $row_number]) DESCRIPTION
Use db2_fetch_row(3) to iterate through a result set, or to point to a specific row in a result set if you requested a scrollable cursor. To retrieve individual fields from the result set, call the db2_result(3) function. Rather than calling db2_fetch_row(3) and db2_result(3), most applications will call one of db2_fetch_assoc(3), db2_fetch_both(3), or db2_fetch_array(3) to advance the result set pointer and return a complete row as an array. PARAMETERS
o $stmt - A valid stmt resource. o $row_number - With scrollable cursors, you can request a specific row number in the result set. Row numbering is 1-indexed. RETURN VALUES
Returns TRUE if the requested row exists in the result set. Returns FALSE if the requested row does not exist in the result set. EXAMPLES
Example #1 Iterating through a result set The following example demonstrates how to iterate through a result set with db2_fetch_row(3) and retrieve columns from the result set with db2_result(3). <?php $sql = 'SELECT name, breed FROM animals WHERE weight < ?'; $stmt = db2_prepare($conn, $sql); db2_execute($stmt, array(10)); while (db2_fetch_row($stmt)) { $name = db2_result($stmt, 0); $breed = db2_result($stmt, 1); print "$name $breed"; } ?> The above example will output: cat Pook gold fish Bubbles budgerigar Gizmo goat Rickety Ride Example #2 i5/OS recommended alternatives to db2_fetch_row/db2_result On i5/OS it is recommended that you use db2_fetch_both(3), db2_fetch_array(3), or db2_fetch_object(3) over db2_fetch_row(3)/db2_result(3). In general db2_fetch_row(3)/db2_result(3) have more issues with various column types in EBCIDIC to ASCII translation, including possible truncation in DBCS applications. You may also find the performance of db2_fetch_both(3), db2_fetch_array(3), and db2_fetch_object(3) to be superior to db2_fetch_row(3)/db2_result(3). <?php $conn = db2_connect("","",""); $sql = 'SELECT SPECIFIC_SCHEMA, SPECIFIC_NAME, ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE, ROUTINE_CREATED, ROUTINE_BODY, IN_PARMS, OUT_PARMS, INOUT_PARMS, PARAMETER_STYLE, EXTERNAL_NAME, EXTERNAL_LANGUAGE FROM QSYS2.SYSROUTINES FETCH FIRST 2 ROWS ONLY'; $stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE)); while ($row = db2_fetch_both($stmt)){ echo "<br>db2_fetch_both {$row['SPECIFIC_NAME']} {$row['ROUTINE_CREATED']} {$row[5]}"; } $stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE)); while ($row = db2_fetch_array($stmt)){ echo "<br>db2_fetch_array {$row[1]} {$row[5]}"; } $stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE)); while ($row = db2_fetch_object($stmt)){ echo "<br>db2_fetch_object {$row->SPECIFIC_NAME} {$row->ROUTINE_CREATED}"; } db2_close($conn); ?> The above example will output: db2_fetch_both MATCH_ANIMAL 2006-08-25-17.10.23.775000 2006-08-25-17.10.23.775000 db2_fetch_both MULTIRESULTS 2006-10-17-10.11.05.308000 2006-10-17-10.11.05.308000 db2_fetch_array MATCH_ANIMAL 2006-08-25-17.10.23.775000 db2_fetch_array MULTIRESULTS 2006-10-17-10.11.05.308000 db2_fetch_object MATCH_ANIMAL 2006-08-25-17.10.23.775000 db2_fetch_object MULTIRESULTS 2006-10-17-10.11.05.308000 SEE ALSO
db2_fetch_array(3), db2_fetch_assoc(3), db2_fetch_both(3), db2_fetch_object(3), db2_result(3). PHP Documentation Group DB2_FETCH_ROW(3)
All times are GMT -4. The time now is 01:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy