Tuesday, August 26, 2008

UNIX - Extracting text between any Two Lines - Updated

Laurent Schneider suggested one liner using AWK unix command - for my last script Extract_Text.sh... see here:



awk '/^CREATE UNIQUE INDEX/{print "-- Create unique index #"++x}/^CREATE TABLE/{print "-- Create table #"++y}/^CREATE (UNIQUE INDEXTABLE)/,/;/{print}' test.sql




/^CREATE (UNIQUE INDEXTABLE)/,/;/{print}: Searches for CREATE UNIQUE INDEX or CREATE TABLE and prints the lines till the first ";" encounters.



/^CREATE UNIQUE INDEX/{print "-- Create unique index #"++x}: Searches for pattern CREATE UNIQUE INDEX and prints "-- Create unique index # and the number of it's occurance".



/^CREATE TABLE/{print "-- Create table #"++y}: Searches for pattern CREATE TABLE and prints "-- Create unique index # and the number of it's occurance".




This is indeed a better and faster than the while read loop. Below is the modified script for download:




Extract_Text_Modified.sh





NOTE:
After downloading this file, please REPLACE &lt ; with < and &gt ; with >
there is no space between &lt and ; or &gt and ;



* Thanks Laurent

Monday, August 25, 2008

UNIX - Extracting text between any Two Lines

I created a script that modifies an sql script in certain logical way. It extracts texts between certain logical lines and sends the output to a new file. You can download the shell script from here and try executing it with the attached test.sql as input. I created this script to alter PeopleSoft Generated AlterByRename sqls into simple CREATE statements.

Extract_Text.sh
usage: ./Extract_text.sh
NOTE: After downloading this file, please REPLACE
&lt ; with <
&gt ; with >
There is no space between &lt and ; or &gt and ;
(I've mentained the space because of issue with blogspot)

test.sql

OCI - Attach Block Volume to Windows VM

Tip: Although creating and attaching Block Storage to a Windows VM is pretty straightforward (OCI documentation is pretty good for that), th...