Please use ***
[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do
not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. Thanks.
Scripting questions generally go in the programming forum. You can use the "report" button to ask the moderators to move it for you.
For better results, always post an example of the input you want to work on, and the output you desire from it. Explain clearly what you're trying to do, any be sure to provide other data necessary to replicate what you want. In this case, what do the
$i and
$ip variables hold and match?
Is the loop really necessary? There are much better options available if all you want is to get the first hit.
expr is also completely superfluous in modern shells, since they all have
integer arithmetic built in.
In any case, a single
awk command will almost certainly do the job you want better than your chain of multiple
grep/sed/cut commands.
Here are a few useful awk references:
http://www.grymoire.com/Unix/Awk.html
http://www.gnu.org/software/gawk/man...ode/index.html
http://www.pement.org/awk/awk1line.txt
http://www.catonmat.net/series/awk-one-liners-explained