i believe, i've been doing an almost identical routine lately to what you've got there. When i first began, i kept getting the same results (and frustration), that you've gotten. The others touched on the key for me in their examples, but i thought, i would elaborate on what's going on.
say, you have... $host = 1.2.3.4
and you search for /$host/
you could get back...
1.2.3.4
11.2.3.4
201.2.3.4
1.2.3.43
1.2.3.42
111.2.3.49
or even... cat1.2.3.4dog
because perl regexes are so greedy in nature. The keys to changing this behavior for me were the addition of -
the caret ^ symbol - which is a beginning-anchor ("nothing before")
and the dollar sign $ - which is an ending-anchor ("nothing after")
these'll let perl know, you are searching for one specific expression. I use'em almost religiously now in those kinds of pattern matches.
assuming that each $host(@ip_host) entry is an ip addy in the same format, i would think, that simply grepping /^$host$/ would work.
either way, hope it works out for you :-)
In reply to Re: How grep IP-addresses that is an exact match?
by wolfi
in thread How grep IP-addresses that is an exact match?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |