CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
regexp master need it

 



salparadise42
New User

Oct 12, 2007, 10:13 AM

Post #1 of 1 (1949 views)
regexp master need it Can't Post

perl noob hoping to write a script to add values to a sql db at work.
Here is the relevant part of code

Code
while (<file2>) { 
40 if (my ($mainbit) =
41 m{
42 ^
43 \s*
44 (?:\b(?:\d{1,3}\.){3}\d{1,3}\b)
45 /
46 (\d{1,2})
47 \s is \s subnetted, \s
48 \d+
49 \s subnets \s*
50 .*
51 $
52 }x) {
53 $lastbit = $mainbit;
54 } elsif (my ($type, $default, $subtype, $netip, $subnetbits, $ad, $metric, $destip, $uptime, $int) =
55 m{
56 ^
57 ([CSIRMBDOE]) # type
58 (\*)? \s+ # is default?
59 ((?:EX)|(?:IA)|(?:N1)|(?:N2)|(?:E1)|(?:E2)|(?:L1)|(?:L2)|(?:ia))? \s* #sub type
60 (\b(?:\d{1,3}\.){3}\d{1,3}\b) #Network address
61 (?:
62 /
63 (\d{1,2}) # subnet bits
64 )?
65 \s
66 \[(\d{1,3}) # adminsitrative distance
67 /
68 (\d{1,10})\] # metric
69 \s via \s
70 (\b(?:\d{1,3}\.){3}\d{1,3}\b) #destaddr
71 (?:
72 , \s
73 ([^,]+) # uptime
74 , \s
75 ([^\s]+) # Exit interface
76 )?
77 .*
78 $
79 }x) {
80 $default = "" unless defined $default;

81 $subtype = "" unless defined $subtype;
82 $uptime = "" unless defined $uptime;
83 $int = "" unless defined $int;
84 $subnetbits = $lastbit unless defined $subnetbits;
85 $count++;
86 push(@networks, "$netip/$subnetbits");
87 #print "$type\t$netip\t$destip\n";
88 }
89 }

Basically im trying to extract individual values from the following output

Code
 4 7600-UT01#show ip route vrf vrfData ospf 
5 69.0.0.0/8 is variably subnetted, 184 subnets, 7 masks
6 O E2 69.4.191.252/30
7 [110/20] via 10.136.217.2, 00:28:33, Serial1/1.7/26:0.1
8 O E2 69.4.191.244/30
9 [110/20] via 10.136.215.2, 00:28:33, Serial1/1.7/24:0.1
10 O E2 69.4.191.240/30
11 [110/20] via 10.136.214.2, 00:28:33, Serial1/1.7/23:0.1
12 O E2 69.4.191.220/30
13 [110/20] via 10.136.236.2, 00:28:33, Serial1/1.8/13:0.1
14 O E2 69.4.191.216/30 [110/20] via 10.136.232.2, 00:28:33, Serial1/1.8/9:0.1
15 O E2 69.4.191.212/30
16 [110/20] via 10.136.203.2, 00:28:33, Serial1/1.7/12:0.1
17 O E2 69.4.191.208/30 [110/20] via 10.136.225.2, 00:28:33, Serial1/1.8/2:0.1
18 O E2 69.4.191.192/28 [110/20] via 10.137.8.2, 00:28:33, Serial1/1.3/9:0.1
19 O E2 69.4.191.176/28 [110/20] via 10.136.226.2, 00:28:33, Serial1/1.8/3:0.1
20 O E2 69.4.191.168/29
21 [110/20] via 10.136.205.2, 00:28:33, Serial1/1.7/14:0.1

It works great for lines where the output is only one line like line 18 of the previous output, but it doesn't match line 20 and 21 because they are in two different lines. So I am looking for one or two solutions.
Have $_ =~ match on a multiline like that and make it one line, or change my regexp to also match on those lines somehow.
Thanks in advance.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives