942,960 Members | Top Members by Rank

Ad:
Nov 5th, 2009
0

OMG... simple question driving me nuts

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Hilliard is offline Offline
5 posts
since Nov 2009
Nov 6th, 2009
0
Re: OMG... simple question driving me nuts
what you are looking for is not clear.

can you please post a sample output of what you require
Reputation Points: 10
Solved Threads: 1
Newbie Poster
versatileint is offline Offline
6 posts
since Jun 2009
Nov 7th, 2009
0
Re: OMG... simple question driving me nuts
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 ' .
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Nov 9th, 2009
0
Re: OMG... simple question driving me nuts
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Hilliard is offline Offline
5 posts
since Nov 2009
Nov 9th, 2009
0
Re: OMG... simple question driving me nuts
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Hilliard is offline Offline
5 posts
since Nov 2009
Nov 10th, 2009
0
Re: OMG... simple question driving me nuts
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!
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: file replacement not working!
Next Thread in Shell Scripting Forum Timeline: Help with grep?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC