Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching for set of numbers

Status
Not open for further replies.

kirk124

Programmer
Apr 15, 2003
26
US
Hi,


Hi ,

I have the following data in a text file:

Net to Media Table
Device IP Address Mask Flags Phys Addr
------ -------------------- --------------- ----- ---------------
hme0 192.45.10.250 255.255.255.255 08:00:09:40:0d:05
hme0 192.45.10.248 255.255.255.255 00:10:83:53:35:08
hme0 css033 255.255.255.255 08:00:20:c0:ca:1d
hme0 sleepy 255.255.255.255 08:00:20:b9:1f:0e
hme0 192.45.10.235 255.255.255.255 00:80:45:22:91:0f
hme0 192.45.10.215 255.255.255.255 00:10:b5:48:9a:7a
hme0 css057 255.255.255.255 00:b0:d0:87:52:19
hme0 192.45.10.162 255.255.255.255 00:b0:d0:87:50:f5
hme0 192.45.10.172 255.255.255.255 00:b0:d0:cd:12:af
hme0 192.45.10.132 255.255.255.255 00:b0:d0:c3:c8:8b
hme0 192.45.10.129 255.255.255.255 00:c0:4f:5a:e1:bf
hme0 192.45.10.143 255.255.255.255 00:b0:d0:c3:c7:d2
hme0 192.45.10.142 255.255.255.255 00:b0:d0:44:9c:78
hme0 192.45.10.156 255.255.255.255 00:b0:d0:75:d1:4d
hme0 192.45.10.153 255.255.255.255 00:c0:4f:59:b6:5b
hme0 css035 255.255.255.255 SP 08:00:20:da:b5:3d
hme0 148.32.32.1 255.255.255.255 08:00:20:a7:24:c5
hme0 148.34.34.3 255.255.255.255 08:00:20:f7:af:32
hme0 192.45.10.71 255.255.255.255 00:60:b0:ec:9a:ba
hme0 192.45.10.69 255.255.255.255 00:60:b0:ec:ca:63
hme0 192.45.10.64 255.255.255.255 00:60:b0:ec:ca:53
hme0 192.45.10.72 255.255.255.255 00:60:b0:ec:22:7e
hme0 192.45.10.63 255.255.255.255 00:60:b0:ec:22:7d
hme0 192.45.10.62 255.255.255.255 00:08:74:ac:16:eb
hme0 css020 255.255.255.255 08:00:20:b9:5b:6b
hme0 catalina 255.255.255.255 08:00:20:86:9a:9e
hme0 224.0.0.0 240.0.0.0 SM 01:00:5e:00:00:00


I want to grab all the number that begins with "192.45.10..." in the second column and put it in an array.

Does anyone knows how to do this with perl.

--thanks
 
open FH, "path/file";
while (<FH>) {
($huh, $ip, $sub, $trash1, $trash2)=split &quot; &quot;,$_;
if (index $ip, &quot;192.45.10&quot; != -1) {
print &quot;$ip&quot;;
}
}

HTH
Paul

BTW - not tested but it'll give you a start
 
my @array = ();
open FILE, &quot;data.txt&quot; or die &quot;Cannot open file data.txt: $!\n&quot;;
while(<FILE>) {
push @array, ($_ =~ m/(192\.45\.10\.\d+)/);
}
close FILE;

print join(&quot;\n&quot;,@array).&quot;\n&quot;;


Barbie
Leader of Birmingham Perl Mongers
 
I like the following idiom. :)

my @array;

open FH, &quot;data.txt&quot; or die &quot;Can't open file data.txt: $!&quot;;
push @array, /(192\.45\.10\.\d+)/ while <FH>;
close FH;

print &quot;$_\n&quot; for @array;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top