The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regular expression [^ ] iengca Shell Programming and Scripting 9 06-18-2008 09:45 AM
Need a regular expression tony3101 Shell Programming and Scripting 4 06-05-2008 03:13 AM
regular expression and awk nickg UNIX for Dummies Questions & Answers 2 08-16-2007 05:23 PM
Regular Expression edog UNIX for Dummies Questions & Answers 5 12-04-2003 02:58 PM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 10:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-24-2007
ynixon ynixon is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 57
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:
Code:
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:
Code:
create table third
(
  BBL_CUSTOMER_NAME      VARCHAR2(32),
);
create table 
forth
(
  BBL_CUSTOMER_NAME      VARCHAR2(32) );
HELP ME

Last edited by ynixon; 05-24-2007 at 11:02 AM..
  #2 (permalink)  
Old 05-24-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,355
You can try something like that :
Code:
awk '
   BEGIN { 
      RS=ORS=";\n"
   }
   /create/ && ! /tablespace/ {
      sub(/^\n*/, "");
      print
   }
    ' inputfile
Jean-Pierre.
  #3 (permalink)  
Old 05-24-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk -v RS=";\n" -v ORS=";\n" ' !/tablespace/ ' filename
  #4 (permalink)  
Old 05-24-2007
ynixon ynixon is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 57
I'd like to try using only grep
  #5 (permalink)  
Old 05-24-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 699
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:
Code:
#!/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:
Code:
% ./s1

create table third
(
  BBL_CUSTOMER_NAME      VARCHAR2(32),
);
create table
forth
(
  BBL_CUSTOMER_NAME      VARCHAR2(32) );
Best wishes ... cheers, drl
  #6 (permalink)  
Old 05-24-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Quote:
Originally Posted by ynixon
I'd like to try using only grep
why is that?
  #7 (permalink)  
Old 05-24-2007
ynixon ynixon is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 57
Quote:
Originally Posted by vgersh99
why is that?
unfortunately the final solution will be used in windows environment ,
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
Sponsored Links
Closed Thread

Bookmarks

Tags
regex, regular expressions

« Random | Http_host »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0