I found one or more problems with the examples given above (could be typos, could be system differences, who knows..)
EDIT: Must have been a death-defying series of typos on my part
as the other methods now work for me.
While this method may be no better, it appears to work for me:
Code:
echo $ip | awk -v RS="." '{if(out != ""){out = out"."}; out = out sprintf("%03u",$0)} END{print out}'
192.168.023.034
Using ORS and/or FS required extra code or just didn't work; this method isn't perfect either, but it adds variety to the thread. And, here's a sed method:
Code:
echo $ip | sed "s/\([0-9]*\).\([0-9]*\).\([0-9]*\).\([0-9]*\)/ printf "%03u.%03u.%03u.%03u" \1 \2 \3 \4 /ge"
I like Kenhelm's method the best, for its simplicity..