On 02/11/08 20:45, Jerrygreat wrote:
>
> Hello, Buddies,
> I must use Unix vim editor to edit a very large xxx.sql file. I have the
> following urgent sytax question, I wonder if any friend can help me a
> liittle....

How large is large? On 32-bit machines, the biggest file Vim can edit is 
two gigabytes. On a 64-bit machine, and considering the size of 
present-day hard disks, a 64-bit version of Vim can edit any file you 
can store.

> (I just bought a vim book, however, I am still not good enough..  )
>
> 1. I have a lot of lines with break like below:
> ALTER TABLE "HCDCNV"."SUBLEDGER_ENTRY" ENABLE CONSTRAINT
> "SUBLEDGER_ENRTY_FK5" ;
> ...
> (how can I change it to )
> ALTER TABLE "HCDCNV"."SUBLEDGER_ENTRY" ENABLE CONSTRAINT
> "SUBLEDGER_ENRTY_FK5" ; ---no break for each line in the whole file.
> (and a liitle more...
>   if I can merge all the lines into one line before ';' in whole file? How?

Joining the whole file into one line, then adding a line break after 
every semicolon, would be practical for a small file but not for a "very 
large" one, so something else must be found. Let's see:

1. Make sure every semicolon is followed by a linebreak with no 
intervening space:

        :%s/;/;\r/g

2. Remove any linebreak not preceded by a semicolon, and replace it by a 
space (to avoid running two words into one):

        :%s/\%(^\|[^;]\)\zs\n/ /

Note: The fact that the linebreak is represented as \n in the search 
pattern and by \r in the replace-by string is not a mistake.

>
>
> 2.I just want to extrat those 'ALTER TABLE ...ENABLE CONSTRAINT..' clause
> (like below as example)in the whole xxx.sql file, and save it to new file
> called '1.sql'
>
> ALTER TABLE "HCDCNV"."SUBLEDGER_ENTRY" ENABLE CONSTRAINT
> "SUBLEDGER_ENRTY_FK5" ;
> ALTER TABLE "PCDCNV"."VALIDASSOCIATION" ENABLE CONSTRAINT
> "FK_VALIDASSOCIATION_01";
> ALTER TABLE "PCDCNV"."VALIDASSOCIATION" ENABLE CONSTRAINT
> "FK_VALIDASSOCIATION_02";
> .....

The following assumes that the preceding joining of lines has been done

        :let save_more = &more
        :set nomore
        :redir > 1.sql
        :%g/^ALTER TABLE\>.*\<ENABLE CONSTRAINT\>/p
        :redir END
        :let &more = save_more

see
        :help let-option
        :help expr-option
        :help 'more'
        :help :redir
        :help :g
        :help :s
        :help pattern.txt

>
>
> 3. in the whole file, there are some 'CREATE TABLE....' clause, like below
>
> CREATE TABLE "HCDCNV"."ADDR_AGREEMENT" ("AGREEMENT_ID" NUMBER,
> "AGREEMENT_CODE" VARCHAR2(64) NOT NULL ENABLE, "AGREEMENT_EFF" DATE
> NOT NULL ENABLE, "CRTN_DT_TMSTMP" DATE NOT NULL ENABLE, "IS_VALID"
> VARCHAR2(1) NOT NULL ENABLE, "CRTN_LGN_ID" VARCHAR2(20) NOT NULL
> ENABLE, "MDFD_DT_TMSTMP" DATE NOT NULL ENABLE, "MDFD_LGN_ID"
> VARCHAR2(20) NOT NULL ENABLE) PCTFREE 10 PCTUSED 80 INITRANS 1
> MAXTRANS 255 STORAGE(INITIAL 1048576 FREELISTS 1 FREELIST GROUPS 1)
> TABLESPACE "CONVTABLES" LOGGING NOCOMPRESS ;
>
> so how can I extract only those 'CREATE TABLE....' clause till ';' from this
> file and save it to a new file, say '2.sql'

also assuming lines have been joined except at semicolons:

        :let save_more = &more
        :set nomore
        :redir > 2.sql
        :%g/^CREATE TABLE\>/p
        :redir END
        :let &more = save_more

>
> 4.
>
> ALTER TABLE "PCDCNV"."VALIDASSOCIATION" ADD CONSTRAINT
> "FK_VALIDASSOCIATION_03" FOREIGN KEY ("OBJECTTYPEUID") REFERENCES
> "OBJECTTYPE" ("OBJECTTYPEUID") ENABLE NOVALIDATE
> ;
>
> How can I extract only those 'ALTER TABLE ....ADD CONSTRAINT' till ';'clause
> from this file and save it as new file '3.sql';

This third case is left as an exercise to the student.

>
>
>
> If any friend can give me an answer, it can give me a lot help to resolve
> urgent need, while I still keep learning it.
>
>
> Thanks a lot in advance..
>
> Jerry

Best regards,
Tony.
-- 
Now that you've read Fortune's diet truths, you'll be prepared the next
time some housewife or boutique-owner-turned-diet-expert appears on TV
to plug her latest book.  And, if you still feel a twinge of guilt for
eating coffee cake while listening to her exhortations, ask yourself
the following questions:

(1) Do I dare trust a person who actually considers alfalfa sprouts a
     food?
(2) Was the author's sole motive in writing this book to get rich
     exploiting the forlorn hopes of chubby people like me?
(3) Would a longer life be worthwhile if it had to be lived as
     prescribed ... without French-fried onion rings, pizza with
     double cheese, or the occasional Mai-Tai?  (Remember, living
     right doesn't really make you live longer, it just *seems* like
     longer.)

That, and another piece of coffee cake, should do the trick.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to