LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-30-2010, 10:50 PM   #1
newbie_0404
LQ Newbie
 
Registered: May 2010
Posts: 13

Rep: Reputation: 0
Bash script: Need some help on how to parse a simple SQL query


newbie_0404

Last edited by newbie_0404; 06-04-2010 at 12:02 AM.
 
Old 05-30-2010, 11:02 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,253

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
So what have you tried so far?
You mention you want a bash script but also that awk is a possibility. Does this mean awk as a subset of the script or an awk script?

You would need to supply more information as well:
1. are we only looking at CREATE TABLE entries?
2. Are there possibly things to be ignored amongst the attr & type (eg the size of type)?
3. etc

Remember, we are not here to do the work but rather help you with where you are stuck.

Reference for bash scripting: tldp.org/LDP/abs/html/
 
Old 05-31-2010, 12:47 AM   #3
orangesky
Member
 
Registered: Jun 2009
Posts: 87

Rep: Reputation: 17
why bother making a bash script to do mysql statements?

if you type mysql -u user -p it will prompt for a password and you can paste your statements right there.
 
Old 05-31-2010, 12:59 AM   #4
newbie_0404
LQ Newbie
 
Registered: May 2010
Posts: 13

Original Poster
Rep: Reputation: 0
newbie_0404

Last edited by newbie_0404; 06-04-2010 at 12:03 AM.
 
Old 05-31-2010, 01:01 AM   #5
newbie_0404
LQ Newbie
 
Registered: May 2010
Posts: 13

Original Poster
Rep: Reputation: 0
newbie_0404

Last edited by newbie_0404; 06-04-2010 at 12:04 AM.
 
Old 05-31-2010, 01:08 AM   #6
alan99
Member
 
Registered: Mar 2010
Distribution: Debian
Posts: 180

Rep: Reputation: 31
Would it not be a better approach to use sql statements (show table or show columns) to obtain the schema of the database rather than parsing some script that may have created that table? The table may have been modified some where along the line.
 
Old 05-31-2010, 01:28 AM   #7
newbie_0404
LQ Newbie
 
Registered: May 2010
Posts: 13

Original Poster
Rep: Reputation: 0
newbie_0404

Last edited by newbie_0404; 06-04-2010 at 12:04 AM.
 
Old 05-31-2010, 01:46 AM   #8
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,324
Blog Entries: 1

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Have you tried using expect?
 
Old 05-31-2010, 07:34 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,253

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Well if it was awk you could use something like:
Code:
awk '/CREATE/{gsub(/(|)/,"");gsub(/,/," ");print $3;for(i=4;i<=NF;i+=2)print $i,$(i+1)}' file
Not tested, but you get the idea.
 
Old 05-31-2010, 07:46 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Some years ago I wrote a Perl program to create DB schemas etc from previously created SQL statements etc. More complex than your requirement.
Personally I'd use Perl, its great for text matching etc.
http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials

Otherwise, I'd guess awk, but as an awk program ie no piping into it.
http://www.grymoire.com/Unix/Awk.html

You could prob do it with just bash, but it'd be fiddly.
 
Old 06-02-2010, 01:31 AM   #11
newbie_0404
LQ Newbie
 
Registered: May 2010
Posts: 13

Original Poster
Rep: Reputation: 0
newbie_0404

Last edited by newbie_0404; 06-04-2010 at 12:04 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Simple parse of html file using bash ericcarlson Linux - Software 2 05-07-2008 10:44 AM
Parse XML in bash script MikeyCarter Linux - Software 1 02-16-2007 02:19 PM
bash script help to parse out text slack guy Linux - Newbie 3 12-30-2004 09:42 AM
Speeding up the script, or the SQL Query? knickers Programming 1 04-13-2004 12:57 PM
ColdFusion - Using a script to build and execute SQL query when a button is clicked Locura Programming 1 02-25-2004 10:59 PM


All times are GMT -5. The time now is 10:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration