Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How can I grep these IP-addresses from these logfiles?

by tcf22 (Priest)
on Oct 04, 2003 at 20:20 UTC ( [id://296573]=note: print w/replies, xml ) Need Help??


in reply to How can I grep these IP-addresses from these logfiles?

#! /usr/bin/perl use strict; #BUILD IP LIST open(IPS, 'ip.txt') || die "Can't open IP.txt: $!\n"; my $iplist = join('|', map {chomp;quotemeta} <IPS>); close(IPS); my $re = qr/$iplist/; #READ IN LOG FILE my @log = map {chomp;$_} <DATA>; #Check for matches my @matches = grep /$re/, @log; print "$_\n" foreach(@matches); __DATA__ 1.1.2.1 1.3.4.5 192.168.0.1 1.2.3.4 4.5.6.7 10.0.0.1
ip.txt
192.168.0.1 1.1.1.1 10.0.0.1
Output:
192.168.0.1
10.0.0.1

Update: Add contents of ip.txt, which made the output make more sense.
Combined 2 map statements into 1 when reading in ip.txt.

- Tom

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://296573]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-19 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found