Index: /trunk/compact-recs.pl
===================================================================
--- /trunk/compact-recs.pl	(revision 888)
+++ /trunk/compact-recs.pl	(revision 889)
@@ -4,5 +4,5 @@
 ##
 # $Id$
-# Copyright 2013-2022 Kris Deugau <kdeugau@deepnet.cx>
+# Copyright 2013-2022,2025 Kris Deugau <kdeugau@deepnet.cx>
 #
 #    This program is free software: you can redistribute it and/or modify
@@ -170,5 +170,13 @@
       # skip existing template within the new template's range
       next if $val =~ m{/\d+$};
-      DNSDB::_template4_expand(\$cmp, $val, \$cidr);
+      if ($cmp =~ /\%-?c/) {
+        # Determine "nth host" index value of $val for %c and %-c
+        my $possible = new NetAddr::IP $val;
+        my $valindex = $possible - $cidr;
+        $valindex-- if $cmp =~ /\%-c/;
+        DNSDB::_template4_expand(\$cmp, $val, \$cidr, $valindex);
+      } else {
+        DNSDB::_template4_expand(\$cmp, $val, \$cidr);
+      }
       $delsth->execute($id) if $cmp eq $host;
       $delcnt++ if $cmp eq $host;
