How to sort for IPs in a certain block in vim
:g/<startpattern>/+1,/<stoppattern>/-1 !sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
For example in bind reverse lookup zones, you have the problem to sort the lines for IPs.
befor
$ORIGIN 147.135.10.in-addr.arpa.
168 PTR vls195.lol.adm.foo.net.
169 PTR vls196.lol.adm.foo.net.
16 PTR vlp115.prod.map.lol.foo.net.
15 PTR vlp105.prod.map.lol.foo.net.
17 PTR vlp114.prod.map.lol.foo.net.
$ORIGIN 148.135.10.in-addr.arpa.
:g/147.135/+1,/148.135/-1 !sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
or better
:g/$ORIGIN\ 0.135.10.in-addr.arpa./+1,/$ORIGIN\ 4.135.10.in-addr.arpa./-1 !sort -n -t . -k 4,1 -k 3,2 -k 2,3 -k 1,4
after
$ORIGIN 147.135.10.in-addr.arpa.
15 PTR vlp105.prod.map.lol.foo.net.
16 PTR vlp115.prod.map.lol.foo.net.
17 PTR vlp114.prod.map.lol.foo.net.
168 PTR vls195.lol.adm.foo.net.
169 PTR vls196.lol.adm.foo.net.
$ORIGIN 148.135.10.in-addr.arpa.
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
is the external sort program
with the options to sort IPs