<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[DHCP Server Dump (Export) - Sorting IP using RegEx]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/14354/can-i-sort-ip-addresses-in-numeric-value">Can I sort IP addresses in numeric value</a></p>
<p dir="auto">When creating DHCP reservations, Microsoft stores them as they are created. The result leads to exports being out of IP sequential order. Here is an alternative solution to my previous (<a href="https://community.notepad-plus-plus.org/post/26434">https://community.notepad-plus-plus.org/post/26434</a>).</p>
<p dir="auto">The alternative method pads the IP with leading Zeros with “undo” option to target just those changes. The prior solution used an <code>\x23</code> (ASCII 23 hash ‘#’) as a RegEx group substitution. However, the “unpad” (undo) I referenced would also remove comments in DHCP dump file, breaking it for importing later.</p>
<p dir="auto">Re: (<a href="https://community.notepad-plus-plus.org/post/25048">https://community.notepad-plus-plus.org/post/25048</a>)<br />
Kudos for the extensibility : <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>  and <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a></p>
<p dir="auto">Here’s my new workflow to DHCP Server: export, pad, sort, unpad, import</p>
<ol>
<li>Export</li>
</ol>
<pre><code>netsh dhcp server dump &gt; "DHCP_Server_Export_%date:~10,4%.%date:~4,2%.%date:~7,2%_%time:~0,2%.%time:~3,2%.%time:~6,2%.%time:~9,2%.txt
</code></pre>
<ol start="2">
<li>
<p dir="auto">Pad (Notepad++ RegEx)<br />
Select Text between “ReservedIp to the Scope”<br />
RegEx Replace All In Selection<br />
SEARCH <code>reservedip ((\d)?(\d)?\d)\.((\d)?(\d)?\d)\.((\d)?(\d)?\d)\.((\d)?(\d)?\d)</code><br />
REPLACE <code>reservedip (?2:0)(?3:0)$1.(?5:0)(?6:0)$4.(?8:0)(?9:0)$7.(?11:0)(?12:0)$10</code><br />
The above effectively changes IP such as 172.20.20.7 --&gt; 172.020.020.007</p>
</li>
<li>
<p dir="auto">Sort (Notepad++ TextFX Tools)<br />
While selection is highlighted, “Sort lines case sensitive (at column)”</p>
</li>
<li>
<p dir="auto">UnPad (Notepad++ RegEx)<br />
While selection is highlighted,<br />
RegEx Replace All In Selection<br />
SEARCH <code>reservedip 0*(\d{1,3})\.0*(\d{1,3})\.0*(\d{1,3})\.0*(\d{1,3})</code><br />
REPLACE <code>reservedip $1.$2.$3.$4</code><br />
The above is needed since <code>netsh exec</code> on script import script file (step 6) fails with IPs having leading zeros. Unfortunate.</p>
</li>
<li>
<p dir="auto">Remove/Purge (PowerShell)<br />
Save/SaveAs Exported Text file as “DHCP_Server_Import…”<br />
Open PowerShell ISE as Administrator (replace ‘x’ as applicable)</p>
</li>
</ol>
<pre><code>Remove-DhcpServerv4Reservation -ComputerName "xxxx.xxx.local" -ScopeId 192.168.xx.0
</code></pre>
<ol start="6">
<li>Import (CMD)<br />
Open elevated Command Prompt</li>
</ol>
<pre><code>netsh exec "DHCP_Server_Import..."
</code></pre>
<p dir="auto">Refresh DHCP tree and reservations are now in order (matching Import file).</p>
<p dir="auto">Hope this helps someone.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/19878/dhcp-server-dump-export-sorting-ip-using-regex</link><generator>RSS for Node</generator><lastBuildDate>Fri, 08 May 2026 14:10:42 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/19878.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Aug 2020 17:59:33 GMT</pubDate><ttl>60</ttl></channel></rss>