title: How to read multiple lines in a text file and pass it to sql script one by one in shell script
body: <p>I do came across a task to read a txt file and pass it to sql file or sql query during run time one by one in a shell script</p>
  
  <p>I do explain more below</p>
  
  <p>I have data in a <code>File.txt</code> file with pipe separated like below(it may n(100 to 1000) numbers, so the script has to read this file and pass value one by one to the sql query to retrieve the records for example if I have 20 records the loop has to read and pass the first and subsequent data to sql query to retrieve data from database </p>
  
  <pre><code>14389056|Alpha
  13467895|Beta
  15679084|Charlie
  </code></pre>
  
  <p>So I wrote script like below</p>
  
  <pre><code>MY_PATH=/home/CBS1/CBS2/sara
  MY_FILE=$MY_PATH/File.txt
  
  var_a=`cat $MY_FILE|wc -l
  if [ "var_a" -gt 0 ]
  then
  IFS=' '
  while read line 
  do
  var_b=`cat MY_FILE|cut -f 1 -d '|'
  var_b=`cat MY_FILE|cut -f 2 -d '|'
  t=`sqlplus -s usr/pwd$host
  select * from table_name where column_name='$var_b' and column_name='$var_c';
  EOF`
  echo $t
  done &lt; $MY_FILE
  </code></pre>
  
  <p>While I am running the above script it's working when the file has one record like below</p>
  
  <pre><code>14389056|Alpha
  </code></pre>
  
  <p>However, when I am having records more than one in the file it passing null values!</p>
  
  <p>I'm missing something? do I need do to any changes in the loop?</p>
  
  <p>Your help is highly appericiated.</p>
  
  <p>Regards
  Tk</p>