VIm…the swiss army knife in editor land..

If you ever find yourself in need of joining lines, because some spool file output went wrong..May I suggest the VI editor?

For example, to get this mess below fixed, follow along..

CREATE UNIQUE INDEX “PIETJE”.”TGBIED110900$IDX1″ ON “PIETJE”.”TGBIED110900″ (NLSSORT(“T$SERN”,’nls_sort=”GENERIC_M”’), “T$UPID”, “T$BPID”, NLSSORT(“T$SUPC”,’nls_sort=”GENERIC_M”’), NLSSORT(“T$SUBC”,’nls_sort=”GENERIC_M”’))
PCTFREE 5 INITRANS 3 MAXTRANS 255 COMPUTE STATISTICS
TABLESPACE “COMP90X_INDX” ;

The editor cuts my lines, but just imagine: we would like to have the create statement on one line, the PCTFREE and TABLESPACE, like below:

CREATE UNIQUE INDEX ….
PCTFREE 5 INITRANS 3 MAXTRANS 255 COMPUTE STATISTICS
TABLESPACE “USER_INDX” ;

Open the spool/text file and enter this:

:g/CREATE/j3

Explanation:
: => editor mode
g => global (go through the whole file)
/ => search for ...
CREATE  => the word we are looking for
/ => what are we supposed to do when we find the word?
j3 =>  join the next 3 lines after the line containing the word.

This helped rescue a file with 2+ million lines, which took me 3 hrs to generate..

Altering the file: 5 secs!

Vim and me? A loving relationship…

Have fun!

Advertisements

About GemsOfProgramming

Beeing a previously enthusiastic Java programmer, I rolled into the Oracle Database Administration world. It turned out I got a knack for this, and since approx. 2000 I'm a full time DBA. My experiences touches lot of Oracle products like Forms and Reports 9/10, JDAPI, Application Server, Weblogic Fusion and of course: Oracle Enterprise Databases, JavaFX, Swing and other Java components.
This entry was posted in Technical Stuff and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s