• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Shell script syntax

Hi,

Im trying to write a script for the following:

I have a file with a list of numbers (over 300)

So I want to input them into a SQL statament:

select * from todo where TODD='89014104254327F';

And them thrown it it a file.

So I thought something like this (not sure of the syntax)

while [ condition until the file finishes ]
do
output=`sqlplus -s ${db_user}/${db_pass}@${SID} <<!
      set heading off
      set feedback off
      select * from todo where TODD=${variable};
      exit;
      !`

${output} >> ultimate_file.txt

some counter for the condition??

done


===================

The file with the numbers looks like this:

525245
252524
252345
234245
242342
123123
144144
.
.


Tks,
joao
0
joaotelles
Asked:
joaotelles
  • 2
  • 2
1 Solution
 
sakmanCommented:
You can do something like this in shell:

for line in `cat filename`
do

    output=...

done

Open in new window

0
 
joaotellesAuthor Commented:
So it would be:

for line in `cat filename`
do

    output=...

done

====

No counter needed?

To put the output in a file is it ok?

${output} >> ultimate_file.txt
0
 
sakmanCommented:
No counter is needed because "cat filename" will just output each line until it is done.

Inside the do/done loop, you want to have:

echo "$output" >>ultimate_file.txt (or ${output} if you prefer)

#
# set your db_user, db_pass, and SID variables
#
for variable in `cat filename`
do
      output=`sqlplus -s ${db_user}/${db_pass}@${SID} <<!
            set heading off
            set feedback off
            select * from todo where TODO=${variable};
            exit;
            !`

      echo ${output} >> ultimate_file.txt

done

Open in new window

0
 
joaotellesAuthor Commented:
tks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now