|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Extract a block of text
Hello all, I am working on a script which should parse a large file called input.txt which contains table definitions, index definitions and comments like these ones: Code:
------------------------------------------------
-- DDL Statements for table "CMWSYS"."CMWD_TEC_SUIVI_TRT"
------------------------------------------------
CREATE TABLE "CMWSYS"."CMWD_TEC_SUIVI_TRT" (
"ORDER_ID" VARCHAR(20) ,
"PERIODE_DATE" VARCHAR(50) ,
"NOM_JOB" VARCHAR(100) ,
"D_START" TIMESTAMP ,
"D_END" TIMESTAMP ,
"T_ELAPSED" TIME ,
"STATUS" VARCHAR(50) )
IN "CMW_DA16DN01" INDEX IN "CMW_IX16DN01" ;Code:
------------------------------------------------
-- DDL Statements for table "CMWSYS"."CMWD_REF_MARCHE_AFFECTATION"
------------------------------------------------
CREATE TABLE "CMWSYS"."CMWD_REF_MARCHE_AFFECTATION" (
"CD_CSM" SMALLINT NOT NULL ,
"CD_SSE_3EME_CAR" CHAR(1) NOT NULL ,
"CD_TYP_PERS" CHAR(3) NOT NULL ,
"DT_VAL_DEB" DATE ,
"CLE_SS_COMPRT" SMALLINT NOT NULL ,
"DT_VAL_FIN" DATE ,
"TOP_COURANT" CHAR(1) ,
"TOP_ANNUL" CHAR(1) ,
"DT_MAJ_ETL" TIMESTAMP )
IN "DIM_DA16DN01" INDEX IN "DIM_IX16DN01" ;
COMMENT ON COLUMN "CMWSYS"."CMWD_REF_ZONE_MONETAIRE"."DT_MAJ_ETL" IS 'Date ETL chargement du flux';
COMMENT ON COLUMN "CMWSYS"."CMWD_REF_ZONE_MONETAIRE"."TOP_ANNUL" IS '1 annulé, 0 sinon';The script should extract each table definition in one separate file (normal txt file) called dbname_tablename.txt. The "dbname" is the first word in the quotation marks after CREATE TABLE statement and the "tablename" is the string characters included in quotation marks after the '.' sign (for this case CMWSYS_CMWD_TEC_SUIVI_TRT or CMWSYS_CMWD_REF_MARCHE_AFFECTATION). All the others definitions (indexes) and the comments should be ignored.. Do you have any idea how I can manage this task? I still have no result with my humble script I am working at. Thanks Last edited by Scrutinizer; 03-07-2013 at 07:32 AM.. Reason: code tags (AGAIN) |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
If you don't provide more clue about the expected format's result, i am afraid people won't be able to help you much.
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Extract a block of text
I edited the description and I guess it should be better now. Thank you, ctsgnb for this observation.
|
|
#4
|
|||
|
|||
|
Depending on your Database, some specific tool should exist to perform such kind of task. I think you should consider this approach rather than "reinventing the wheel"
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Extract a block of text
I do not intend to reinvent the wheel, but to find a useful tool to make this conversion. I found some tools, but all of them are not free of use, unless you pay for the license.
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Could you show a larger sample? Telling where the definitions begin and end can be awkward unless they all begin the same way, with a comment...
You can use awk for this though, I'm pretty sure. It has a "block" mode, where it can read entire sections delimited by blank lines. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Extract a block of text
Attached you will find the input.txt file containing all the table definitions.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grepping text block by block by using for loop | anushree.a | Shell Programming and Scripting | 12 | 09-24-2012 06:46 AM |
| How to extract block from a file? | ran123 | Shell Programming and Scripting | 5 | 05-04-2011 08:54 AM |
| [Awk] Extract block of with a particular pattern | sandeepk1611 | Shell Programming and Scripting | 7 | 02-15-2011 03:50 PM |
| Extract a block of text?? | marcozd | Shell Programming and Scripting | 10 | 01-25-2011 03:40 PM |
| extract block in file | sskb | UNIX for Dummies Questions & Answers | 5 | 10-25-2001 10:29 AM |
|
|