#!/bin/sh

# The idea is:
# - get the list of leases
# - using awk, reorganize them as 1 entry per line with IP address first
# - sort
# - using awk, recreate the "nvram set static_leases" command entry
# - last 'awk' command is to remove the trailing " "

nvram set static_leases="`nvram get static_leases | sed 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)/.\1./g' | tr ' ' '\n' | sort -n -k2,2n -k3,3n -k4,4n -k5,5n -t. | tr '\n' ' ' | sed 's/\.\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)\./\1/g' | sed 's/^ //'; echo`"

# verify that it worked with this command which works both in terminal and Commands GUI.
#nvram get static_leases | tr ' ' '\n'
