Reading csv and executing queries

hi all,

i have a csv file in which some queries are there and through a shell script
i am reading and trying to excute them but it is not working properly

my csv file is like this

Tid,table,query,values
1,PRD_FRG_FILE_JRNL,SELECT SWI_ID,FT_SWI
2,PRD_FRG_FILE_JRNL,SELECT COUNT(1),1


and my script is like this


#!/bin/bash -xv
hdr=1
while IFS=',' read -r f1 f2 f3 f4
do      if [ "$hdr" ]
        then    # Skip the 1st line from the input file.
                hdr=""
                continue
        fi

        Tid=$f
        Table=$f2
        query=$f3
        value=$f4
done < excel.txt
sqlplus $IB_RTE_CONN_STR << EOF
$query from $table;
EXIT
EOF


can any one please help

You had "Table" for a variable, instead of "table":

#!/bin/bash -xv
IB_RTE_CONN_STR=scott/tiger
hdr=1
while IFS=',' read -r f1 f2 f3 f4
do      if [ "$hdr" ]
        then    # Skip the 1st line from the input file.
                hdr=""
                continue
        fi

        Tid=$f
        table=$f2
        query=$f3
        value=$f4
sqlplus -s /nolog << EOF
connect $IB_RTE_CONN_STR
$query from $table;
EXIT
EOF
done < file
$ cat myScript
#!/bin/bash
#-xv
IB_RTE_CONN_STR=scott/tiger
hdr=1
while IFS=',' read -r f1 f2 f3 f4
do      if [ "$hdr" ]
        then    # Skip the 1st line from the input file.
                hdr=""
                continue
        fi

        Tid=$f
        table=$f2
        query=$f3
        value=$f4
sqlplus -s /nolog << EOF
connect $IB_RTE_CONN_STR
$query from $table;
EXIT
EOF
done < file

$ cat file
Tid,table,query,values
1,EMP,SELECT MGR,FT_SWI
2,DEPT,SELECT DNAME,1

$ ./myScript

       MGR
----------
      7902
      7698
      7698
      7839
      7698
      7839
      7839
      7566

      7698
      7788

       MGR
----------
      7698
      7566
      7782

14 rows selected.


DNAME
--------------
ACCOUNTING
RESEARCH
SALES
OPERATIONS
1 Like

Hi,
i used the previous script to compare to the values returned by the query with the values in the csv file.like this

!/bin/bash
hdr=1
while IFS=',' read -r f1 f2 f3 f4
do      if [ "$hdr" ]
        then    # Skip the 1st line from the input file.
                hdr=""
                continue
        fi

        Tid=$f
        table=$f2
        query=$f3
        value=$f4
val_1=$( sqlplus -s rte/rtet2@rel76t2 << EOF
set heading off
set feedback off
$query from $table;
EXIT
EOF
)
val_4=`echo $val_1 | tr '\n' ' '`

echo "val_5 : $val_4 "
if [ $val_4 == $value ]
then
   echo "test pass"
else
   echo "test fail"
fi

done < excel.txt



it gave the result like this


val_5 : EXINZTE
test pass
val_5 : 1
test pass
val_5 : SP2-0042: unknown command "from " - rest of line ignored.
./read.sh: line 24: [: too many arguments
test fail
val_5 : SP2-0042: unknown command "from " - rest of line ignored.
./read.sh: line 24: [: too many arguments
test fail

but i only want the result like this

val_5 : EXINZTE
test pass
val_5 : 1
test pass

but why two more values are compared , how to resolve it

---------- Post updated at 02:04 AM ---------- Previous update was at 02:02 AM ----------

the csv file used is like this

Tid,table,query,values
1,PRD_FRG_FILE_JRNL,SELECT SWI_ID,EXINZTE
2,PRD_FRG_FILE_JRNL,SELECT CONVERTED_RECS,1