The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Unix scripting pl help sree11 UNIX for Dummies Questions & Answers 1 12-05-2007 11:46 PM
UNIX scripting moe2266 UNIX for Dummies Questions & Answers 5 08-06-2007 12:41 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 09:12 AM
Help With Unix Scripting. hella UNIX for Dummies Questions & Answers 1 08-04-2003 11:18 AM
UNIX Scripting wolf UNIX for Dummies Questions & Answers 7 07-31-2001 02:37 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-14-2008
shaik shaik is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 7
Unhappy unix awk scripting

Hi
can anyone pls help me out in knowing how a array of elements which are fetched from database is passed to the awk program.

Something like this

#!/bin/sh

AMT[]=`sqlplus -s usrname/pswd <<EOD
set pagesize 0 feedback off verify off heading off echo on
select amount from tablename where condition;
EOD`

noofrec=`sqlplus -s usrname/pswd <<EOD
set pagesize 0 feedback off verify off heading off echo on
select count(*) from tablename where condition;
EOD`

echo "$AMT[]" $noofrec | awk '
BEGIN
{
new=$1;
printf "%d" ,new; //this works fine with 2nd argumnet but dont know how
printf the arrays values?
}

{
printf "%d" ,AMT???
}'END
  #2 (permalink)  
Old 02-14-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,099
awk

Hi,

I am not sure why you will process like this, why not spool the sql result to a file and then process the file. This seems easy to release.

Here we can treat the spool file as the array, it should be ok for you. Just try it.


Code:
sqlplus -s ops\$global/developer@sf2a <<!
spool a.txt
select exl_name from exchange_list where rownum<=5; (your sql here)
spool off
!
while read line
do
what you want to do with the each result.
done < a.txt

  #3 (permalink)  
Old 02-15-2008
shaik shaik is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 7
Arrow Re

thank you for the idea,

this works fine but my reqiremnt asks for more than one data to be fetched which also works but same needs to be parsed in the awk program.

My requirement says of priting the values of each elements one by one to a file that too in a loop.


regards
Mohima
  #4 (permalink)  
Old 02-15-2008
roden roden is offline
Registered User
  
 

Join Date: Nov 2002
Posts: 14
How about:

echo $noofrec "${AMT[@]}"|awk '{nrec=$1;for (i=2;i<=NF;i++) {print $i;shift}}'

  #5 (permalink)  
Old 02-15-2008
shaik shaik is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 7
Re:

it works fine,

i have to print the elements of the array in the loop.

regards
Mahi
  #6 (permalink)  
Old 02-15-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,893
No, you don't need "the loop". xargs will do that for you.


Code:
echo $noofrec "${AMT[@]}"| xargs

  #7 (permalink)  
Old 02-19-2008
shaik shaik is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 7
Exclamation need more suggestions

well it would be bit difficult to satisfy a requirement which requires something like this

#!/bin/sh

//iam reading the data for amounts from database

AMT[]=`sqlplus -s usrname/pswd <<EOD
set pagesize 0 feedback off verify off heading off echo on
select amount from tablename where condition;
EOD`

//writing to a file created at a specifed direcotry using a awk program

echo "$AMT[]" $noofrec | awk '
BEGIN
{
new=$1;
------------------------------------------------------------------
//i need to write the contents of the array in the file (which is created
at a specified location) in a loop that prints in each line contents of amount AMT[] array(as long as elements are there).

------------------------------------------------------------------
hence my problem is to print the elements in the array one by one in lines which are equivalent to no of elements in the array.

for i furthur read this file for processing

Iam able to get the contents into the array from db but couldnt print it in the file

please need suggestions asap.

Regards
Mahima
--------------------------------------------------------------------

printf "006%d" ,new; //this works fine with 2nd argumnet but dont know how
printf the arrays values?
}

{
printf "%d" ,AMT???
}'END
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0