LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-29-2004, 11:29 AM   #1
philipz
LQ Newbie
 
Registered: Apr 2004
Posts: 25

Rep: Reputation: 0
MySQL connection in shell script - how to?


List,

I have a file named 'hits' om my drive that looks like:

43 10.10.10.1
79 10.11.12.12
678 10.23.34.45
...

At the moment I create a MySQL batch file from the 'hits' file like above and run the batch query:
SELECT * FROM sitelist WHERE address LIKE 10.10.10.1
SELECT * FROM sitelist WHERE address LIKE 10.11.12.12
SELECT * FROM sitelist WHERE address LIKE 10.23.34.45
...

The result then looks like:
Rome
Amsterdam
Brussels

while I'd better like something like this:
43 10.10.10.1 Rome
79 10.11.12.12 Amsterdam
678 10.23.34.45 Brussels
...

I have no clue how to combine the 'hits' with the result of the query... Anyone an idea?

Kind regards,

Philip
 
Old 04-29-2004, 05:03 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
SELECT '10.10.10.1,* FROM sitelist WHERE address LIKE 10.10.10.1
 
Old 04-29-2004, 05:09 PM   #3
philipz
LQ Newbie
 
Registered: Apr 2004
Posts: 25

Original Poster
Rep: Reputation: 0
I think I miss something here...
Would that code go into the batch file?

Would that give me the following output:
43 10.10.10.1 Rome
for every entry?
 
Old 04-29-2004, 07:04 PM   #4
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Ah.. I missed the '43' part and misunderstood the rest.

Efectively you want to join two files (where the first one is called 'hits' and second one generated by those select lines)?
You can use 'paste' to do this.

Something like 'theScriptThatDoesTheSelectThing | paste hits -'
See 'man paste' or 'info paste' for details.
 
  


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
Database connection using Shell Script sumitarun Linux - Newbie 2 05-09-2010 12:18 PM
PHP Shell Script (with MySql) Tony Empire Programming 1 09-20-2005 09:59 AM
MySQL in a shell script?! zaubara Programming 2 05-31-2004 05:27 PM
How to Shell Script auto ftp connection? mtn356 Linux - General 4 03-18-2004 07:31 PM
How get a mysql shell response in a script. philipina Programming 3 03-16-2004 11:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:03 AM.

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