LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 08: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, 05: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


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


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration