parse a file to find an ip address
hi,
i need an efficient shell script program that should parse a file to find all ip address within it and ping those ip to check whether they r reachable r not.... thanks, gcg... |
Quote:
Code:
for i in `cat $1 | grep '\b[0-9]\.[0-9]\.[0-9]\.[0-9]\b'`; ping $i; done |
hi ,
its giving an error ./t6: line 3: syntax error near unexpected token `ping' ./t6: line 3: `ping $line' |
Code:
for i in `cat $1 | grep '\b[0-9]\.[0-9]\.[0-9]\.[0-9]\b'`; do ping $i; done |
gurucg, just an hint: when testing a script put an echo in front of any command inside a loop, as in
Code:
for i in <some expression here> Code:
egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' |
95se I couldn't get your regex to work?
This is what I came up with: $for i in $(grep -Eo "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}" yourfile);do ping -c2 -w2 $i;done |
Another way to do it:
grep -Eo "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}" yourfile| while read i;do ping -c2 -w2 $i done |
#
# Internet host table # 127.100.100.1 localhost 129.0.0.1 b1-lr-09 loghost 10.42.76.1 b1-lr-09-e0 # ADD - DO NOT MODIFY this is the contents of myfile(host1)..... even though i tried above code .... i am getting some errors.. so please help me out from this |
i am making use of solaris
|
which book(or websites) do i refer for shell script programming .....
|
|
Indeed, the usage of regexp on solaris is a bit more restricted and grep/egrep has less options than their counterparts on linux. Parsing an host file as the one you posted could be done by simply
Code:
awk '{print $1}' | grep -v \# Code:
awk '{print $1}' | grep ^[0-9] Regarding a good shell programming guide, I would suggest the "Bash Guide for beginners" http://www.tldp.org/LDP/Bash-Beginne...tml/index.html, but it is based on the Bourne Again Shell and you may feel a little confused if you're working on solaris, since it implements the Bourne Shell /bin/sh. A lot of BASH features are not available in SH. |
Here. You may need to change the ping command, but hopefully this will work better for you.
Code:
#!/usr/bin/python |
thanks it worked....
|
Quote:
Code:
awk '!/#/{print $1}' file Code:
awk '!/^[0-9]/{print}' file |
All times are GMT -5. The time now is 03:11 PM. |