The UNIX and Linux Forums  

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
Perl Pattern Matching !!! Help maxmave Shell Programming and Scripting 0 06-03-2008 08:05 PM
AWK pattern matching, first and last smb_uk Shell Programming and Scripting 10 12-27-2007 09:03 PM
Perl: Pattern Matching a HASH variable pondlife Shell Programming and Scripting 1 04-10-2006 04:31 PM
perl pattern matching vs. grep junkmail426 Shell Programming and Scripting 0 09-28-2005 11:40 AM
pattern matching + perl question Optimus_P Shell Programming and Scripting 1 12-05-2003 07:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2007
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 139
Question perl pattern matching

hi i am trying to get digits inside brackes from file , whose structure is defined below


Code:
CREATE TABLE TELM
(SOC_NO                 CHAR (3)     NOT NULL,
 TXN_AMOUNT          NUMBER (17,3)  
 SIGN_ON_TIME        CHAR (8)     
 TELLER_APP_LIMIT   NUMBER (17,3)  
 FIL01                     CHAR (11)    
CONSTRAINT TELMPK
PRIMARY KEY (SOC_NO,
             TELLER_NO),
CONSTRAINT TELMUK_02
UNIQUE      (SOC_NO,
             TELLER_NO,
             SUP_TELLER));

i want only digits inside bracket i am able to get digits from bracket (which is BOLD) if there is only one digit eg :

Code:
[(SOC_NO                 CHAR (3)     NOT NULL,]

with following code


Code:
 if (/^.*(CHAR|NUMBER)\s*.*$/) {
             $_ =~ s/ DEFAULT(.*)// ;
             print "$_\n" ;
         if (/^.*\((\d+)\).*$/) {
             print "one:$1\n" ;
          }elsif (/^.*\((\d\d),(\d)\).*$/) {
             print "two :$2\n" ;
          }

but i am not able to get digits if they are specified with comma in between like :

Code:
TXN_AMOUNT          NUMBER (17,3)

for above i want 17 in 1 varaible and 3 in other but i m not able to manage it i get only digit specified after "," 3 for above case.
  #2 (permalink)  
Old 09-28-2007
foo.bar foo.bar is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 5
Hi zedex,

supponing that the file you are reading is called 'temp', you can use this code to get both numbers in brackets:



Code:
open(FILE, "< temp");                                                                                                                                           
while ( $r = <FILE>) {
        if ($r =~  /^.*\s+.*\s+\((\d+)\)/) {
                print "\$1= $1\n";
                }
        elsif ($r =~  /^.*\s+.*\s+\((\d+),(\d+)\)/) {
                print "\$1= $1\n";
                print "\$2= $2\n";
                }
        }

Sergio
  #3 (permalink)  
Old 09-30-2007
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 139
thanx it worked as i wanted
Closed Thread

Bookmarks

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 08:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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