Visit Our UNIX and Linux User Community


Extract a paragraph


 
Thread Tools Search this Thread
Operating Systems Linux Extract a paragraph
# 1  
Old 06-04-2008
Extract a paragraph

Hi ,
Unix.com has been life saver for me I admit Smilie
I am trying to extract a paragraph based on matching pattern "CREATE TABLE " from a ddl file . The paragraphs are seperated by blank line .

Input file is

#cat zip.20080604.sql1
CONNECT TO TST103

SET SESSION_USER OPSDM002

SET CURRENT SCHEMA OPSDM002


CREATE TABLE "OPSDM002"."DIM_ZIP" (
"ZIP_CD" CHAR(5) NOT NULL ,
"ZIP_TYP_SRC_CD" CHAR(1) NOT NULL ,
"ZIP_TYP_CD" CHAR(1) NOT NULL ,
"ZIP_ROW_END_DT" DATE NOT NULL ,
"ZIP_ROW_EFF_DT" DATE NOT NULL ,
"ZIP_LST_2_CD" CHAR(2) NOT NULL ,
"ZIP_FST_3_CD" CHAR(3) NOT NULL ,
"UPDT_DT" DATE NOT NULL WITH DEFAULT CURRENT DATE ,
"ST_NUM_CD" CHAR(2) NOT NULL ,
"ST_ABBR_CD" CHAR(2) NOT NULL ,
"PST_CNTY_NM" VARCHAR(25) NOT NULL ,
"PST_CNTY_CD" CHAR(3) NOT NULL ,
"LOAD_DT" DATE NOT NULL WITH DEFAULT CURRENT DATE ,
"HCFA_CNTY_NM" VARCHAR(30) NOT NULL ,
"HCFA_CNTY_CD" CHAR(4) NOT NULL ,
"CTY_NM" VARCHAR(28) NOT NULL )
COMPRESS YES
IN "TSOPS03" INDEX IN "TSOPIX03"

CREATE INDEX "OPSDM002"."IDX1_ST_CD" ON "OPSDM002"."DIM_ZIP"
("ST_ABBR_CD" ASC)
ALLOW REVERSE SCANS

CREATE UNIQUE INDEX "OPSDM002"."PK1_ZIP_CD" ON "OPSDM002"."DIM_ZIP"
("ZIP_CD" ASC)
CLUSTER ALLOW REVERSE SCANS

ALTER TABLE "OPSDM002"."DIM_ZIP"
ADD CONSTRAINT "PK1_ZIP_CD" PRIMARY KEY
("ZIP_CD")

CREATE ALIAS "OP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OSEL01"

GRANT SELECT ON TABLE "OPSDM002"."DIM_ZIP" TO GROUP "CLOSEL02"

GRANT CONTROL ON TABLE "OPSDM002"."DIM_ZIP" TO GROUP "UHCDMDBA"

GRANT SELECT ON TABLE "OPSDM002"."DIM_ZIP" TO GROUP "CLOSEL04"

GRANT SELECT ON TABLE "OPSDM002"."DIM_ZIP" TO GROUP "CLOSEL05"

GRANT SELECT ON TABLE "OPSDM002"."DIM_ZIP" TO GROUP "SELCOE01"

GRANT CONTROL ON TABLE "OPSDM002"."DIM_ZIP" TO USER "ESHIRLE "

GRANT CONTROL ON TABLE "OPSDM002"."DIM_ZIP" TO USER "SNIETER "

GRANT CONTROL ON TABLE "OPSDM002"."DIM_ZIP" TO USER "LTREXL1 "

GRANT CONTROL ON TABLE "OPSDM002"."DIM_ZIP" TO USER "RSMIT11 "

GRANT CONTROL ON TABLE "OPSDM002"."DIM_ZIP" TO USER "KJOHNS5 "

GRANT CONTROL ON TABLE "OPSDM002"."DIM_ZIP" TO USER "AMENSEY "

COMMIT WORK

CONNECT RESET

TERMINATE

Desired output is


CREATE TABLE "OPSDM002"."DIM_ZIP" (
"ZIP_CD" CHAR(5) NOT NULL ,
"ZIP_TYP_SRC_CD" CHAR(1) NOT NULL ,
"ZIP_TYP_CD" CHAR(1) NOT NULL ,
"ZIP_ROW_END_DT" DATE NOT NULL ,
"ZIP_ROW_EFF_DT" DATE NOT NULL ,
"ZIP_LST_2_CD" CHAR(2) NOT NULL ,
"ZIP_FST_3_CD" CHAR(3) NOT NULL ,
"UPDT_DT" DATE NOT NULL WITH DEFAULT CURRENT DATE ,
"ST_NUM_CD" CHAR(2) NOT NULL ,
"ST_ABBR_CD" CHAR(2) NOT NULL ,
"PST_CNTY_NM" VARCHAR(25) NOT NULL ,
"PST_CNTY_CD" CHAR(3) NOT NULL ,
"LOAD_DT" DATE NOT NULL WITH DEFAULT CURRENT DATE ,
"HCFA_CNTY_NM" VARCHAR(30) NOT NULL ,
"HCFA_CNTY_CD" CHAR(4) NOT NULL ,
"CTY_NM" VARCHAR(28) NOT NULL )
COMPRESS YES
IN "TSOPS03" INDEX IN "TSOPIX03"




Thanks ,
# 2  
Old 06-04-2008
With sed you can print a section between two regular expressions like this:

Code:
sed -n '/^CREATE TABLE/,/^IN/p' file

Regards
# 3  
Old 06-04-2008
You ROCK Mr Franklin !

Previous Thread | Next Thread
Test Your Knowledge in Computers #790
Difficulty: Easy
The AND gate is a basic digital logic gate that implements logical conjunction.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script to extract paragraph with globs in it

Hi, Its been a long time since I have used Bash to write a script so am really struggling here. Need the gurus to help me out. uname -a Linux lxserv01 2.6.18-417.el5 i have a text file with blocks of code written in a similar manner ******* BEGIN MESSAGE ******* Station /... (12 Replies)
Discussion started by: dsid
12 Replies

2. Shell Programming and Scripting

How to extract a paragraph containing a given string?

Hello: Have a very annoying problem: Need to extract paragraphs with a specific string in them from a very large file with a repeating record separator. Example data: a file called test.out CREATE VIEW view1 AS something FROM table1 ,table2 as A, table3 (something FROM table4) FROM... (15 Replies)
Discussion started by: delphys
15 Replies

3. UNIX for Dummies Questions & Answers

Extract paragraph that contains a value x<-30

I am using OSX. I have a multi-mol2 file (text file with coordinates and info for several molecules). An example of two molecules in the file is given below for molecule1 and molecule 2. The total file contains >50,000 molecules. I would like to extract out and write to another file only the... (2 Replies)
Discussion started by: Egy
2 Replies

4. Shell Programming and Scripting

Compare a paragraph

I know this is a challenging, its about comparing a 3 paragraph, from a whois command, i want to print what is the data that is not unique, example below is the admin phone and techphone, the rest is the same.it will print the correct and wrong # whois google.com| sed -n '/Registry Registrant... (3 Replies)
Discussion started by: kenshinhimura
3 Replies

5. Shell Programming and Scripting

How to grep paragraph?

Hi, I have A file like this: >Contig1 AAAAAAATTTTTTCCCAATATATGAT ATATATAEATATATAT >Contig2 AAAAAAATTTTTTCCCAATATATGAT ATATATAEAATTTTTAATTTTTTCCCA ATCCCAAATATATAT >Contig3 AAAAAAATTTTTTCCCAATATATGAT ATATATAEAATTTTTAATTTTTTCCCA ATCCCAAATAAATTTTTTCCCAATAT ATGATATATATAEAATTTTTAATTTTT... (3 Replies)
Discussion started by: the_simpsons
3 Replies

6. Shell Programming and Scripting

How to extract multiple line in a paragraph? Please help.

Hi all, The following lines are taken from a long paragraph: Labels of output orbitals: RY* RY* RY* RY* RY* RY* 1\1\GINC-COMPUTE-1-3\SP\UB3LYP\6-31G\C2H5Cr1O1(1+,5)\LIUZHEN\19-Jan-20 10\0\\# ub3lyp/6-31G pop=(nbo,savenbo) gfprint\\E101GECP\\1,5\O,0,-1.7 ... (1 Reply)
Discussion started by: liuzhencc
1 Replies

7. UNIX for Dummies Questions & Answers

Output text from 1st paragraph in file w/ a specific string through last paragraph of file w/ string

Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string. Previously, I was outputting just each paragraph with that search string with: cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Discussion started by: carpenn
2 Replies

8. Shell Programming and Scripting

Pattern in a paragraph

Hi, I have read similar questions and I was not able to get a solution, so please help :) I have two files: 1-Pattern file contains list of patterns pattern1 pattern2 pattern3 pattern4 .... pattern# 2-input file in the format >hdhfshsdfjhpattern1xmbxmbxnmv... (4 Replies)
Discussion started by: tbakheet
4 Replies

9. UNIX for Dummies Questions & Answers

Split a paragraph

Hi, Consider the following paragraph. This is line1. This is line2, This is last line. I need the output as 4:This is last line. i.e The line after the blank line should be displayed along with line number. I am a unix begineer.Any one please help me to solve this problem (3 Replies)
Discussion started by: Sekar1
3 Replies

10. Shell Programming and Scripting

help, using awk to get paragraph

Hi, I'm trying to find pattern in log file. I'm using awk to search the pattern and print the paragraph. And it's not working well like I want. The file actually is TCAP message, it has format like this : ... ... ... ***************************************** INCOMING TCAP MESSAGE At... (6 Replies)
Discussion started by: kunimi
6 Replies

Featured Tech Videos