How to store query multiple result in shell script variable(Array)

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to store query multiple result in shell script variable(Array)
# 1  
Old 10-30-2007
Question How to store query multiple result in shell script variable(Array)

Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable.




here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array).

# 2  
Old 10-31-2007
One way

let i=0
set -A arr 

echo "
SELECT fld1 
 from TABLEA;
" | sqlplus -s $USER/$PWD | \
while read line
     let i=$i+1

# 3  
Old 11-01-2007
Bug Thanks jim

Smilie You have given reply is very usefull. again thanks to you.

Just in Below code I have change array box with [] and add new code for print the array member.


let i=0
#set -A arr

echo "select param_value
from control_param
where pgm_name = 'EXS_PROCESS';
" | sqlplus -s ${ora_user}/${ora_passwd}@${ORACLE_SID} | \
while read line
if [[ $i -gt 2 ]]
let i=$i+1
echo "Array Variable is Filled Up"
echo " Total no. of member ${#arr[@]} "
echo "Print the Array member"
while [ $i -lt ${#arr[@]}-1 ]
print ${arr[$i]}
(( i=i+1 ))
echo "After Array Print"
# 4  
Old 11-01-2007
Question Would like to ask more thing. How Can I cond. check, pattern matchig and cp file

Here, Situation is I have arr[] array. suppse
arr[1]=SPCS contains
I want to if this pattern(arr[0] or arr[1]) match in ../Innovation dir's file then this file copy --> zip format --> into ../zipdir dir.
If pattern is not found then copy into ../archive dir area

I have tried below code...but not running. I feel , step 6/7 might be modified but how...please help me.

1. i=0
2. for j in `ls ../Innovation`
3. do
4. while [ $i -lt ${#arr[@]}-1 ]
5. do
6. # awk /${arr[$i]}/ { `cp $j ../archive`; } $j
7. source_dir=$($j | head -1 | grep -i ${arr[$i]} | cp ../Innovation/$j ../archive)
8. done
# 5  
Old 11-06-2007
Processing Command line Parameteres in to array

I need to get files names passed to a script. Here number of files passed may vary
like MyScript.ksh file1 file2 file3..... so on

I am writting script somthing like this

set -A Files

while (i<=$#)
let i=i+1

Is this correct way doing this. Is there any other way.
Please let me know

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to loop and store in array

I'm trying to achieve the follwoinig with no luck. Find the directories that are greater than 50GB in size and pick the owner of the directory as I would like to send an alert notification. du -sh * | sort -rh 139G Dir_1 84G Dir_2 15G Dir_3 ls -l Dir_1 drwx------ 2... (3 Replies)
Discussion started by: 308002184
3 Replies

2. Shell Programming and Scripting

Bash to store result in variable for other lines in script to use

I can not figure out how to capture the $filename variable store by the bash. #!/bin/bash # oldest folder stored as variable for analysis, version log created, and quality indicators matched to run dir=/home/cmccabe/Desktop/NGS/test find "$dir" -maxdepth 1 -mindepth 1 -type d -printf... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Store result variable

Friends have the following problem: cat $PATH_DAT/mr.txt | nawk 'BEGIN { CantPnt=0; NumReg=0; FS="|" } { NumReg++ CantPnt=CantPnt+int($2) } END{ printf... (5 Replies)
Discussion started by: tricampeon81
5 Replies

4. Programming

Query result from shell script

Hi, I wrote the below script to get the query result from a Syabase DB. isql -s -U **** -P **** SYBASE SERVERNAME USE ***(Database name in Sybase) @command.sql But im not getting the output. Can anyone help me on this (2 Replies)
Discussion started by: rohan G
2 Replies

5. Shell Programming and Scripting

Store values from a file into an array variable in Shell

Dear All, I have been trying to do a simple task of extracting 2 fields from the file (3 rows) and store it in an array variable. I tried with: #! /bin/bash ch=`cut -f10 tmp.txt` counter=0 for p in $pid do c=${ch} echo "$c ..$counter" counter=$((counter+1))... (2 Replies)
Discussion started by: ezhil01
2 Replies

6. Shell Programming and Scripting

Assign zero to strings that don't appear in block, store result in AWK array

Hi to all, I have this input: <group> <x "2">Group D</x> <x "3">Group B</x> <x "1">Group A</x> </group> <group> <x "1">Group E</x> <x "0">Group B</x> <x "1">Group C</x> </group> <group> ... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

7. Shell Programming and Scripting

Script to store the variable in a table or array.

Hi, I have few variable say 10 ex:- l_pc_291334_01_0_01_00.cmp l_pc_441133_50_0_02_00.cmp l_pc_441133_55_0_02_00.cmp Each variable value is coming via loop on a table. I want to create a script that stores these value to a table or array ( But one by one not all at one time as... (4 Replies)
Discussion started by: amitkumar.b2
4 Replies

8. Shell Programming and Scripting

How to put db2 query result into an array in shell script?

Hello, Can someone please advise me how to put the db2 query reult into an array? For example, the query reults are: string A string B string C Then how do I put them into array=string A array=string B ... (2 Replies)
Discussion started by: hanul
2 Replies

9. Shell Programming and Scripting

In a csh script, can I set a variable to the result of an SQLPLUS select query?

Can someone tell me why I'm getting error when I try to run this? #!/bin/csh -f source ~/.cshrc # set SQLPLUS = ${ORACLE_HOME}/bin/sqlplus # set count=`$SQLPLUS -s ${DB_LOGIN} << END select count(1) from put_groups where group_name='PC' and description='EOD_EVENT' and serial_number=1;... (7 Replies)
Discussion started by: gregrobinsonhd
7 Replies

10. Shell Programming and Scripting

Prase a file and store and result to an array

Dear all, I have a file having the following formats: ThreadFail=Web1=1234 ThreadFail=Web2=2345 ThreadFail=Web3=12 ConnectionFail=DB1=11 ConnectionFail=DB2=22 The number of lines will be different from every time . How can I parse the file and store the result to an a array inside... (6 Replies)
Discussion started by: youareapkman
6 Replies
Login or Register to Ask a Question