I need to insert data from a file to another. I need this to form an sql query file which will consist of 50.000 INSERT INTO sentences.
my sql query file will consist of 50.000 times the below line consecutively:
insert into subscriber (BLINDID,NAME,SURNAME,EMAIL,USER_AUTHORIZATIONID,REM_REWARD,STATUS,IS_BLACKLISTED) values ('DATA','name','surname','DATA@test.com','1','1000','3','0');
I need to insert a given list of Subscribers into the places i specifed as DATA above. how can i manage this? The given data consists of 50.000 numbers. Any suggestion, solution wellcomes.
Note: I tried with MS Excel but coudlnt make it because it senses the characters " ', @" in the queries as special formula characters. I tried data generator program also but failed
We will avoid letting shell see the SQL query because it looks like Shell syntax. We'll just use Shell to sequence external commands.
Assuming your list of numbers is in "example.dat" and your skeleton SQL query line is in "example.skl" we can generate the lines by swapping the string "DATA" for a number from "example.dat" and append to "example.sql".
#!/bin/ksh
>example.sql
cat example.dat | while read NUMBER
do
sed -e "s/DATA/${NUMBER}/g" example.skl >> example.sql
done
sorry but after running the command the example.sql file is getting empty. If i remove the part
>example.sql
and run it it works but replacing NUMBER with each DATA on each line , not replacing with the real numbers.
Please post the shell script you ran and a few lines of sample input data (with anything confidential changed).
What version of unix are you using? What shell?