[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] scripting challenge du'jour



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?

ifconfig | sed -n "/inet /s/\
.*:\([^ ]*\)\
.*:\([^ ]*\)\
.*:\([^ ]*\)\
/\1\/\3\t\2/p"

--Joe