[ale] scripting challenge du'jour
Richard Kolkovich
sarumont at sigil.org
Thu Jul 6 12:14:48 EDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 07/06/06 11:59, Joe Steele declared:
> Richard Kolkovich wrote:
>> On 07/05/06 19:19, Jim Popovitch published:
>>> What's the fastest, cleanest, most optimized, shell script (non perl,
>>> etc) method to take the output of ifconfig and produce a list that
>>> resembles this:
>>>
>>> 192.168.4.5/255.255.255.0 192.168.4.255
>>> 172.16.8.12/255.255.0.0 172.16.255.255
>>>
>>>
>>> Go!
>>>
>>> -Jim P. (TIA ;-))
>>
>> ifconfig | grep inet\ | sed -e 's/:/\ /g' | sed -e '/127.0.0.1/d' | awk
>> - -F\ '{print $3"/"$7"\t\t"$5}'
>>
>
> Would it not be more efficient to use sed only once and avoid the grep
> and awk?
Ahh...yes. Probably. ;) I will be the first to admit, though, that my
sed knowledge is very minimal. I know how to do a few things with it,
and this fit within the realm of that knowledge. awk&sed are tops on my
list to delve into after tonight (end of summer semester!).
An elegant solution, though.
>
> ifconfig | sed -n "/inet /s/\
> .*:\([^ ]*\)\
> .*:\([^ ]*\)\
> .*:\([^ ]*\)\
> /\1\/\3\t\2/p"
>
> --Joe
>
- --
Richard Kolkovich
sarumont at sigil.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFErTb4KTYpNZ5U71kRArf4AJ9cXqXsF4jN084QpCjejHaOK9Gp/QCfUoeN
aSptetgdFxvBof5pMNzXWU4=
=GbVx
-----END PGP SIGNATURE-----
More information about the Ale
mailing list