LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-16-2009, 07:59 PM   #1
pcock
LQ Newbie
 
Registered: Sep 2004
Location: Sydney, Australia
Distribution: Archlinux
Posts: 16

Rep: Reputation: 0
Question text processing to modify sql create script


I have a large number of sql scripts that I'd like to process.
Code:
CREATE TABLE WAREHOUSE_OBJECT
(
  OBJECT_ID          numeric(15)   NOT NULL,
  OBJECT_IDENTIFIER  char(32)      NOT NULL
);

CREATE UNIQUE INDEX  S_WAREHOUSE_OBJECT_PK ON  S_WAREHOUSE_OBJECT
(CONFIG_ID);

ALTER TABLE  S_WAREHOUSE_OBJECT ADD(  --remove open bracket here
  CONSTRAINT S_WAREHOUSE_OBJECT_PK
 PRIMARY KEY
 (CONFIG_ID));  -- remove last close bracket here
I'd like to remove open/closed brackets (at ALTER TABLE) so it looks like this.

Code:
CREATE TABLE WAREHOUSE_OBJECT
(
  OBJECT_ID          numeric(15)   NOT NULL,
  OBJECT_IDENTIFIER  char(32)      NOT NULL
);

CREATE UNIQUE INDEX  S_WAREHOUSE_OBJECT_PK ON  S_WAREHOUSE_OBJECT
(CONFIG_ID);

ALTER TABLE  S_WAREHOUSE_OBJECT ADD 
  CONSTRAINT S_WAREHOUSE_OBJECT_PK
 PRIMARY KEY
 (CONFIG_ID);
I tried something like this in awk but not sure how to eliminate the brackets
Code:
BEGIN {OFS=" "}
  $1 =="ALTER"      { x=$0 }
  $1 =="CONSTRAINT" { y=$0}
  $1 =="PRIMARY"    { z=$0}
  $1 =="((" {print x, y, z, $0}
 
Old 03-17-2009, 04:42 AM   #2
pcock
LQ Newbie
 
Registered: Sep 2004
Location: Sydney, Australia
Distribution: Archlinux
Posts: 16

Original Poster
Rep: Reputation: 0
I found a way to fix this

sed 's/ADD(/ADD/'
sed 's/));/);/'
 
  


Reply

Tags
awk, processing, script, sql, text



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
bash script to create text in a file or replace value of text if already exists knightto Linux - Newbie 5 09-10-2008 11:13 PM
Create a script that will modify a text file KSUA Linux - General 5 03-16-2008 08:31 AM
Can sub processing modify the parent's Gtk Widgets? asnoka Programming 2 12-24-2005 03:35 AM
Create text file with a script zael Programming 3 06-02-2004 03:27 AM
text processing Gantrep Linux - General 4 02-17-2003 10:37 PM

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

All times are GMT -5. The time now is 06:28 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