Kindly use code tags as per forum rules while posting any command/codes/Inputs in your posts, following may help you in same.
grep -Eo '[0-9]{15}' filename1 > demo.txt
### To print only the select statements following.
awk '{print "select * from tablename where ID= " $0}' demo.txt
### To take output in a output file if happy with above print command.
awk '{print "select * from tablename where ID= " $0}' demo.txt > output.txt
### In case you need your id inclosed within ' then following may help.
awk -vs1-"'" '{print "select * from tablename where ID= " s1 $0 s1}' demo.txt
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
When i execute the following in my script (named demon_script.sh):
awk '{print "select * from apsdi-apaction where request_id= " $0}' demo.txt
i get following error in output file:
SP2-0553: Illegal variable name "=000000000019879".
SP2-0223: No lines in SQL buffer.
SP2-0734: unknown command beginning "grep -Eo '..." - rest of line ignored.
SP2-0734: unknown command beginning "awk '{prin..." - rest of line ignored.
no rows selected
Well, I'm now trying the following script where I'm trying to run a .sql file from this script. But when i open the output file everything is blank. Why is this so?
1.demon file contains the string which I'm able to cut for the 15 digit ID.
2.demo.txt file contains the list of IDs as follows:
000000000019879
000000000039043
3.output.sql file contains following:
select * from apsdi-apaction where request_id= 000000000039043
select * from apsdi-apaction where request_id= 000000000019879
4.variable.txt file should contain the output of above sql statements, but the file appears blank.
Please let know what changes are to be made in above script to make it work. How do i excute the .sql file from above script. Any other alternative will also work.
There are two issues I see:
A SQL-Statement is terminated by a semicolon, which seems to be missing in output.sql.
A minus sign should be avoided in table names. If it is present the table name has to be put into double quotes. The double quotes make the reference to the table case sensitive, so make sure you reference it the way it was created (the user_tables view tells you the correct name).