The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find pattern, delete line with pattern and line above and line below nickg Shell Programming and Scripting 4 01-29-2009 01:38 PM
find pattern delete line with pattern and line above and line below nickg UNIX for Dummies Questions & Answers 1 01-28-2009 06:46 PM
comment/delete a particular pattern starting from second line of the matching pattern imas Shell Programming and Scripting 4 10-13-2008 03:37 AM
modify a particular pattern starting from second line of the search pattern imas UNIX for Dummies Questions & Answers 1 10-12-2008 02:19 PM
need for loop to include fields as one line prkfriryce Shell Programming and Scripting 8 03-23-2007 12:49 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-22-2009
rajan_san rajan_san is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 39
Include Line Before Pattern Using Sed / Awk

Hi,

I have a sql file that runs something like this

vi Test.sql

REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM PUBLIC;

REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM DEMO_READ;

REVOKE SELECT ON DEMO_USER.DEMO_NOMINEE_TEST FROM DEMO_READ;

REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM DEMO_APP_RL;

REVOKE SELECT ON DEMO_USER.DEMO_NOMINEE_TEST FROM DEMO_APP_RL;

Prompt Drop SYNONYM DEMO_NEWS;
DROP SYNONYM DEMO_USER.DEMO_NEWS;

Prompt drop View DEMO_NOMINEE_TEST;
DROP VIEW DEMO_USER.DEMO_NOMINEE_TEST;

Prompt drop Function SQC_SAMP;
DROP FUNCTION DEMO_USER.SQC_SAMP;

Prompt Type DEMO_ID_REC;
-- Difference Details :
-- Actual Compared # of Uppercase Lowercase White Other
-- Length Length Lines Letters Letters Space Chars
-- ******************************************************************
-- Comp * 99 72 5 13 40 26 20 *
-- Ref * 132 97 7 32 40 34 26 *
-- ******************************************************************

Prompt Type DEMO_ID_REC;
--
-- DEMO_ID_REC (Type)
--
-- Dependencies:
-- STANDARD (Package)
--
CREATE TYPE DEMO_USER.DEMO_id_rec AS OBJECT
(
LINK_ID varchar2(12),
DEMO_ID varchar2(50),
SAMPLE_FLG CHAR(1)
)
/

SHOW ERRORS;

Prompt Type STRINGTABLETYPE;
--
-- STRINGTABLETYPE (Type)
--
-- Dependencies:
-- STANDARD (Package)
--
CREATE OR REPLACE TYPE DEMO_USER."STRINGTABLETYPE" AS TABLE
OF VARCHAR2 (255)
/

SHOW ERRORS;

Basically the Script must look for All Lines that have either CREATE TYPE / CREATE OR REPLACE TYPE and must pick the type name which is usually
3rd Word for Lines with CREATE TYPE TYPENAME and 5th word for lines containing CREATE OR REPLACE TYPE TYPENAME

The script must generated a DROP TYPE TYPENAME FORCE; and Place this DROP Command just before the CREATE / CREATE OR REPLACE Type commands.

Like in the above case the expected outcome is

vi out.sql

REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM PUBLIC;

REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM DEMO_READ;

REVOKE SELECT ON DEMO_USER.DEMO_NOMINEE_TEST FROM DEMO_READ;

REVOKE EXECUTE ON DEMO_USER.SQC_SAMP FROM DEMO_APP_RL;

REVOKE SELECT ON DEMO_USER.DEMO_NOMINEE_TEST FROM DEMO_APP_RL;

Prompt Drop SYNONYM DEMO_NEWS;
DROP SYNONYM DEMO_USER.DEMO_NEWS;

Prompt drop View DEMO_NOMINEE_TEST;
DROP VIEW DEMO_USER.DEMO_NOMINEE_TEST;

Prompt drop Function SQC_SAMP;
DROP FUNCTION DEMO_USER.SQC_SAMP;

Prompt Type DEMO_ID_REC;
-- Difference Details :
-- Actual Compared # of Uppercase Lowercase White Other
-- Length Length Lines Letters Letters Space Chars
-- ******************************************************************
-- Comp * 99 72 5 13 40 26 20 *
-- Ref * 132 97 7 32 40 34 26 *
-- ******************************************************************

Prompt Type DEMO_ID_REC;
--
-- DEMO_ID_REC (Type)
--
-- Dependencies:
-- STANDARD (Package)
--

DROP TYPE DEMO_USER.DEMO_id_rec FORCE;

CREATE TYPE DEMO_USER.DEMO_id_rec AS OBJECT
(
LINK_ID varchar2(12),
DEMO_ID varchar2(50),
SAMPLE_FLG CHAR(1)
)
/

SHOW ERRORS;

Prompt Type STRINGTABLETYPE;
--
-- STRINGTABLETYPE (Type)
--
-- Dependencies:
-- STANDARD (Package)
--

DROP TYPE DEMO_USER."STRINGTABLETYPE" FORCE;

CREATE OR REPLACE TYPE DEMO_USER."STRINGTABLETYPE" AS TABLE
OF VARCHAR2 (255)
/

SHOW ERRORS;

Any shell script compatible with ksh on Solaris 8 would be fine.

Thanks,
Rajan
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0