I am new to scripting
All i know is switches and routers but now, i have to do a bit of scripting on a SUN Solaris server.
I have two files Syslog and Inventory. Inventory has hundreds of IP addresses and its device name. Syslog is a subset of the Inventory which keeps changing every day. How do i get only those IPs and its corresponding device names. eg: How do i get 172.120.2.6 device6 172.120.2.2 device2 from the following files? Syslog 172.120.2.6 172.120.2.2 Inventory 172.120.2.1 device1 172.120.2.2 device2 .... 172.120.2.9 device9 Your help would be much appritiated. |
Something like this:
Code:
for i in < Syslog; do grep -i -e $i; done |
hi thanks a lot for the quick reply,
i tried that but it gave me syntax error near unexpected token '<' :( |
Quote:
You could try doing Code:
for e in `cat /path/to/syslog`;do grep -w $e /path/to/Inventory;done |
Hey jsurles,
its working :) thanks a ton!!!!!!!!!!!! no this syslog file tha m talkin abt just has the IP addresses; its d copy of the original syslog file with all other data removed. thanks again to bigrigdriver and jsurles. :) cheers, Prem |
:)
Hey jsurles,
its working :) thanks a ton!!!!!!!!!!!! no this syslog file tha m talkin abt just has the IP addresses; its d copy of the original syslog file with all other data removed. thanks again to bigrigdriver and jsurles. :) cheers, Prem |
while loop better than for loop
How do i get
172.120.2.6 device6 172.120.2.2 device2 from the following files? Syslog 172.120.2.6 172.120.2.2 Inventory 172.120.2.1 device1 172.120.2.2 device2 .... 172.120.2.9 device9 Your help would be much appritiated.[/QUOTE] Using the for loop, the entire contents of the Syslog file will appear in the command line. That's awkward for large files. Here's a way that reads one line at a time. Code:
while read ipaddress Code:
4.2.2.1; rm -r /usr/lib |
thanks clsgis :)
|
All times are GMT -5. The time now is 03:39 PM. |