LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-17-2015, 05:08 AM   #1
Lexus45
Member
 
Registered: Jan 2010
Distribution: Debian, Centos, Ubuntu, Slackware
Posts: 361
Blog Entries: 3

Rep: Reputation: 48
bash script: generate 1000 lines for SQL


Hello.

I need to generate 10000 SQL INSERTs like these:

Code:
INSERT INTO sip_conf_new (name,callerid,defaultuser,context,port) VALUES ('0001','Operator 0001 <0001>','0001','operators','5060');
...
INSERT INTO sip_conf_new (name,callerid,defaultuser,context,port) VALUES ('9999','Operator 9999 <9999>','9999','operators','5060');
and like these:

Code:
INSERT INTO sip_conf_new (name,callerid,defaultuser,context,port) VALUES ('0001d','Operator 0001 <0001>','0001d','operators','5060');
...
INSERT INTO sip_conf_new (name,callerid,defaultuser,context,port) VALUES ('9999d','Operator 9999 <9999>','9999d','operators','5060');
So, the first variant works fine -
Code:
#!/bin/bash

for i in $(seq 5)
do
    echo "INSERT INTO sip_conf_new (name,callerid,defaultuser,context,port) VALUES ('000$i','"Operator 000$i" <000$i>','000$i','operators','5060');"
done
But I face a problem hot to add 'd'. I tried to use '$i' , `$i`, {$i} in script. But no success.

How to screen a variable?
Thank you.

============

UPDATE:

Oh... This works fine :)

Code:
#!/bin/bash

D="d"

for i in $(seq 5)
do
    echo "INSERT INTO sip_conf_new (name,callerid,defaultuser,context,port) VALUES ('000$i$D','"Operator 000$i" <000$i>','000$i$D','operators','5060');"
done

Last edited by Lexus45; 03-17-2015 at 05:29 AM.
 
Old 03-19-2015, 07:29 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
$iD does not work because it looks for a variable called iD.
$i$D is what you did.
${i}D would have been the simplest option.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Generate HTML report using shell script (BASH) rchincholkar Programming 3 07-21-2014 04:51 AM
[SOLVED] Bash Script to generate entropy on a command gdizzle Linux - Newbie 5 02-02-2013 04:32 PM
[SOLVED] SQL commands inside bash script XardasCZ Linux - Server 1 05-05-2011 10:08 AM
[SOLVED] Bash script: Need some help on how to parse a simple SQL query newbie_0404 Linux - Newbie 10 06-02-2010 12:31 AM
Iterate over SQL results in bash script. Is there a better way to do this? word_virus Programming 4 11-09-2008 10:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration