-2

I have a below sql query.

select * from table where name in ('${name});

I have a requirement to automate this as here i need to pass the string value name from txt file. The text file contains the differnet special characters and i have some 200 names in the text file as follows. 3" - 11" DCBA-1234 5"-8" ABC MNOP-3765 8"-16" LMNOP ABCD-9964 ABC XYZ JKLM-1212 XYZ-1673

And my below code is not fetching the complete string value, How to achieve this?

for name in `cat file.txt`
do
select * from table where name in ('${name});
done

Any insights would be more helpful!!

Thanks Much!

Samah
  • 1
  • 1
  • 2
  • This is trying to run `select` as a command, not pass it to a database -- which is to say that you're leaving out some very pertinent bits. – Charles Duffy Sep 23 '17 at 19:42
  • BTW, see [Why you don't read lines with `for`](http://mywiki.wooledge.org/DontReadLinesWithFor) and [BashFAQ #001](http://mywiki.wooledge.org/BashFAQ/001). – Charles Duffy Sep 23 '17 at 19:43

1 Answers1

0
while read line;
do
    select * from table where name in $line
done < file.txt

try if this works.

Junior Dussouillez
  • 2,327
  • 3
  • 30
  • 39
abhishek phukan
  • 751
  • 1
  • 5
  • 16