OMG... simple question driving me nuts

Reply

Join Date: Nov 2009
Posts: 5
Reputation: Hilliard is an unknown quantity at this point 
Solved Threads: 0
Hilliard Hilliard is offline Offline
Newbie Poster

OMG... simple question driving me nuts

 
0
  #1
18 Days Ago
Hey guys,

Just trying to do a simple shell script to generate a query line... can someone tell me why this does not work?

Shell Scripting Syntax (Toggle Plain Text)
  1. for e in `cat file.txt`; do echo INSERT INTO \`omstest_omstest\`.\`GEN2_FIELD\` VALUES \(NULL, \'$e\', \'$e\', \'4\', \'2009-10-05 00:00:00\', \'0\' \'0\'\)\;; done;
  2.  

if you take out the $ before each of the e's, I get exactly what I am looking for... except of course there is an e where I want the variable to be.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 6
Reputation: versatileint is an unknown quantity at this point 
Solved Threads: 1
versatileint versatileint is offline Offline
Newbie Poster
 
0
  #2
18 Days Ago
what you are looking for is not clear.

can you please post a sample output of what you require
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #3
17 Days Ago
What shell are you using, and what error are you receiving?

It seems to work for me:
Shell Scripting Syntax (Toggle Plain Text)
  1. sk@svn:/tmp$ for e in `cat file.txt`; do echo INSERT INTO \`omstest_omstest\`.\`GEN2_FIELD\` VALUES \(NULL, \'$e\', \'$e\', \'4\', \'2009-10-05 00:00:00\', \'0\' \'0\'\)\;; done;
  2. INSERT INTO `omstest_omstest`.`GEN2_FIELD` VALUES (NULL, 'ABC', 'ABC', '4', '2009-10-05 00:00:00', '0' '0');
  3.  

Some shells do not like to evaluate $vars unless they are in a " , not a single ' .
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 5
Reputation: Hilliard is an unknown quantity at this point 
Solved Threads: 0
Hilliard Hilliard is offline Offline
Newbie Poster
 
0
  #4
14 Days Ago
I'm using bash... No errors... but the moment I put a $var in place of the two e's, my output gets all jumbled up... and only the last line of the file prints correctly... it is almost like it is reading a new line that is not there... or at least that I am not seeing.

What shell did you use? Did you try it with more than one line in the test file?
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 5
Reputation: Hilliard is an unknown quantity at this point 
Solved Threads: 0
Hilliard Hilliard is offline Offline
Newbie Poster
 
0
  #5
14 Days Ago
rofl... ha ha I'm a newb. The problem was with the text file not the commands. Should have been the first thing I checked

Thanks everyone who tried to help.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #6
14 Days Ago
I'm glad you got it working

Please mark this thread as solve as you have found your solution to the issue and good luck!
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC