1748109 Members
4111 Online
108758 Solutions
New Discussion юеВ

Re: Script help

 
SOLVED
Go to solution
Diesel
Occasional Contributor

Script help

Hello,

I would like to know how to search through the host table to match computers on a particular subnet, then to give the total number matched at the end using a while loop or something (my scripting knowledge is very limited).

Any ideas would be greatly appreciated.
3 REPLIES 3
Pete Randall
Outstanding Contributor

Re: Script help

How about a simple grep/wc?

grep xxx.xxx.xxx /etc/hosts |wc -l


Pete

Pete
Jeff_Traigle
Honored Contributor
Solution

Re: Script help

This could get a bit more complex depending on how your subnets are configured. Generally, you can do something like this, however:

grep -c ^WWW.XXX.YYY. /etc/hosts

-c returns the count instead of the matches (saves the piping of grep to wc)

^ only matches if the address is at the beginning of the line (avoids grabbing commented lines)
--
Jeff Traigle
Diesel
Occasional Contributor

Re: Script help

Thanks guys! That's what I needed.

And thanks Jeff for the detailed explanation. It helps the newbies like myself.