Reputation: 487
Is there an efficient way to use grep
in the following command that I am running, since I want to use only Perl's grep
?
@found = grep { !/$IP/ } `$SSH $IPs[0] netstat -Aan | /bin/grep 1010`;
Basically, I am connecting to a fileserver, executing netstat
command and grep IP addresses containing 1010. Then on this output I need to use grep
to find a specific IP address.
Can this be done somehow using only one Perl command?
Upvotes: 0
Views: 47
Reputation: 85767
Sure, you can do this:
@found = grep { /1010/ && !/$IP/ } `$SSH $IPs[0] netstat -Aan`;
The condition you use in grep
can be not just an arbitrary expression, but even a full block of code if need be.
Upvotes: 3