help in running while loop inside a shell script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help in running while loop inside a shell script
# 1  
Data help in running while loop inside a shell script

I have an input file at ./$1.txt
with content of seq numbers like :
1234567890
1234589700
.
.
so on..

I need to take each seq nbr from the input file ,run the query below:

select ackname,seqnbr from event where event_text like '%seqnbr( from the input file)'

and redirect the query output to a file :log.txt

this has to be done for all seq nbr's in the input file.
Can anyone please help me out in this:-( Smilie Smilie
# 2  
Code:
xargs printf "select ackname,seqnbr from event where event_text like '%%%s'\n" <$1.txt

# 3  
Quote:
Originally Posted by hergp
Code:
xargs printf "select ackname,seqnbr from event where event_text like '%%%s'\n" <$1.txt

I have tried it and it resulted an error:

SP2-0734: unknown command beginning "xargs prin..." - rest of line ignored.

code snippet I have used
Code:
#!/bin/ksh
db_user=`echo $DB_USER_NAME`
db_pwd=`echo $DB_PASSWORD`
db_sid=`echo $TWO_TASK`
if [ $# -ne 1 ]; then
  echo "\tUsage: MoveUsageProcessing  <BC Log file Name>"
  exit 1
  else
 BCLogFileName=$1
 fi
 grep -i  'MoveUsage daemon needs to run on this account before it can be billed'  $1 |awk -F\| '{for(i=0;++i<=NF;) if($i ~ /Acct/) print substr($i,6)}' > ./$1.txt
echo " log file path is : './$1.txt' ";
a=`sqlplus -s $db_user/$db_pwd@$db_sid << EOF
xargs printf "select  ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like'%%%s'\n" <$1.txt
EOF`

# 4  
Quote:
Originally Posted by rkrish
I have tried it and it resulted an error:
SP2-0734: unknown command beginning "xargs prin..." - rest of line ignored.
xargs and printf are shell commands, not SQL commands.
# 5  
Quote:
Originally Posted by hergp
xargs and printf are shell commands, not SQL commands.
What are the changes to be made to make it work:-/
# 6  
You need something like this (untested):
Code:
xargs printf "select ackname,seqnbr from event where event_text like '%%%s';\n" <$1.txt |
    sqlplus -s $db_user/$db_pwd@$db_sid

This assumes, that your SQLTERMINATOR is ';'.
# 7  
try this: (not tested)
Quote:
#!/bin/ksh
db_user=$DB_USER_NAME
db_pwd=$DB_PASSWORD
db_sid=$TWO_TASK
if [ $# -ne 1 ]; then
echo "\tUsage: MoveUsageProcessing <BC Log file Name>"
exit 1
else
BCLogFileName=$1
fi
grep -i 'MoveUsage daemon needs to run on this account before it can be billed' $1 |awk -F\| '{for(i=0;++i<=NFSmilie if($i ~ /Acct/) print substr($i,6)}' > ./$1.txt
echo " log file path is : './$1.txt' ";

sqlplus -s /nolog |&
print -p "connect $db_user/$db_pwd@$db_sid"
print -p "SPOOL output.txt"

while read var_ack_party_name
do
print -p "select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%"$var_ack_party_name"'
done
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #911
Difficulty: Easy
In C, we can get the address of a variable as follows: pointer = &variable;
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a Boolean variable which succeed and failed inside the if loop in shell script ?

I have if loop with multiple variable value check in if loop. How can i print only if loop satisfied variable and its value in shell script ? I dont want to check each variable in if loop. That makes my script larger. if ] then echo "Only satisfied variable with value" ... (3 Replies)
Discussion started by: prince1987
3 Replies

2. Shell Programming and Scripting

Running a script as root but with different users inside

Hi All, my script.sh has the below lines, and i need to run the script as root or wam. please tell me if this will work #!/bin/bash sudo -t wam /usr/local/wam/stopwam -r ------- this needs run as wam user /usr/local/web/stopweb -a --- this needs to run as... (18 Replies)
Discussion started by: nanz143
18 Replies

3. Shell Programming and Scripting

If else condition inside for loop of awk command in UNIX shell scripting

Hi , Please excuse me for opening a new thread i am unable to find out the syntax error in my if else condition inside for loop in awk command , my actual aim is to print formatted html td tag when if condition (True) having string as "failed", could anyone please advise what is the right... (2 Replies)
Discussion started by: karthikram
2 Replies

4. Shell Programming and Scripting

Running .sh file inside a shell script

Hello, You might help a newbie like me, I am trying to run a .sh inside my shell script. After running that I need to execute below commands. Here's how my scripts looks like. Hope you can help: #!/bin/sh cd $ORACLE_HOME/owb/bin/unix ./OMBPlus.sh ---> goes to OMB+> directory cd... (10 Replies)
Discussion started by: aderamos12
10 Replies

5. Shell Programming and Scripting

How to increment date using "for loop" in format MMDDYY inside the shell script?

Need to increment the date from "currentdate + 90days" inside the for loop (i=1 to i=50) (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

6. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

7. Windows & DOS: Issues & Discussions

How to log current timestamp inside a for loop in windows shell?

below is the output where i'm getting the same times tamp throughout the loop., where i'm expecting that to log the current time stamp.. C:\Users\ilango>for /l %i in (1,1,5) do echo for %i C:\Users\ilango>echo for 1 for 1 C:\Users\ilango>echo for 2 for 2 C:\Users\ilango>echo... (1 Reply)
Discussion started by: ilan
1 Replies

8. Shell Programming and Scripting

Running a unix script(which is calling another script inside that) in background

Hi all, I am having a script ScriptA which is calling a script ScriptB in the same server and copying files to second server and have to execute one script ScriptC in the second server. THis First script ScriptA is the main script and i have to execute this process continously. for Keeping... (2 Replies)
Discussion started by: rohithji
2 Replies

9. Shell Programming and Scripting

C Shell - Command Inside a Loop

I have a command nested in some while loops to parse some data that looks something like this. while ($condition) while ($condition) ... gzcat /dir/$fileName.gz | grep $searchString > out_file end end On the first loop, the command is executed properly (and takes maybe 10... (3 Replies)
Discussion started by: hobbers
3 Replies

10. UNIX for Dummies Questions & Answers

running sed inside script file

i am substituting some text in the xml file using sed, on shell directly it works fine, but when i run it inside script file, it say, the function cant be parsed, i think the prob is due to xml file, kindly help (4 Replies)
Discussion started by: bajaj111
4 Replies

Featured Tech Videos