regular expression across some lines

I am trying to use regular expression to identify ONLY the commands that hasn't the word "tablespace" within it. a command starts with "create table" and ends with ; (semicolon)

example file:

create table first tablespace ;
create table second
(
  BBL_CUSTOMER_NAME      VARCHAR2(32),
a tablespace af
);
create table third
(
  BBL_CUSTOMER_NAME      VARCHAR2(32),
);
create table 
forth
(
  BBL_CUSTOMER_NAME      VARCHAR2(32) );

the match should be:

create table third
(
  BBL_CUSTOMER_NAME      VARCHAR2(32),
);
create table 
forth
(
  BBL_CUSTOMER_NAME      VARCHAR2(32) );

HELP ME

You can try something like that :

awk '
   BEGIN { 
      RS=ORS=";\n"
   }
   /create/ && ! /tablespace/ {
      sub(/^\n*/, "");
      print
   }
    ' inputfile

Jean-Pierre.

awk -v RS=";\n" -v ORS=";\n" ' !/tablespace/ ' filename

I'd like to try using only grep

Hi.

I think that grep will not cross newlines, so that you would need to place your commands each on a single line. There is a note in my man grep page about using perl regular expressions, but that it is undocumented. The awk and perl scripts can make use of settable record boundaries.

Here's a perl quickie:

#!/bin/sh

# @(#) s1       Demonstrate perl quickie for unmatched string across lines.

FILE=${1-data1}

perl -wn -e 'BEGIN{$/=";"} print if not /tablespace/' $FILE

exit 0

And running this on your sample contained in file data1:

% ./s1

create table third
(
  BBL_CUSTOMER_NAME      VARCHAR2(32),
);
create table
forth
(
  BBL_CUSTOMER_NAME      VARCHAR2(32) );

Best wishes ... cheers, drl

why is that?

unfortunately the final solution will be used in windows environment :frowning: ,
I am not planning to use Perl because it will need installations in all PCs.
the nuances of regular expression is almost the same in all other languages.
So the convenient solution will be vbscript.

Since I know you are ACEs I decided to ask you :slight_smile:

clean and simple