Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: String searching in file

by Laurent_R (Canon)
on Feb 09, 2018 at 22:07 UTC ( #1208866=note: print w/replies, xml ) Need Help??

in reply to String searching in file

I think that the best way is to load your file into a hash (each IP as a key, the hash value doesn't matter), close the file; then add each IP in your array to the hash (a hash will remoce duplicates anyway); once you've finished that, just write the hash keys (i.e. unique IP addresses) to a file (or to the same file if you're confident that it works OK).

A quick untested example:

open my $IN, "<", $awsLists or die "could not open $awsLists $!"; my %hash = map { chomp; $_ => 1 } <$IN>; close $IN; chomp @command; # just in case you need it. Note: you could choose a b +etter name for your array $hash{$_} = 1 for @command; open my $OUT, ">", "$awsLists.out" or die "could not open $awsLists.ou +t $!"; print "$_\n" for keys %hash; close $OUT;
Using a hash lookup will be usually be much faster than greping your file or its content many times.

Replies are listed 'Best First'.
Re^2: String searching in file
by cbtshare (Scribe) on Feb 09, 2018 at 23:04 UTC
    thanks, will test it out.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2020-01-28 11:24 GMT
Find Nodes?
    Voting Booth?