<?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[How to remove ALL the duplicates WITHOUT deleting the empty lines?]]></title><description><![CDATA[<p dir="auto">I’ve tried several formulas to remove duplicates and they either change the total number of lines in the file or don’t remove all the duplicates.</p>
<p dir="auto">Does anyone know a formula that removes ALL the duplicates WITHOUT deleting the empty lines?</p>
<p dir="auto">THANK YOU.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/25227/how-to-remove-all-the-duplicates-without-deleting-the-empty-lines</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 06:22:24 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/25227.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 10 Dec 2023 11:05:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Tue, 12 Dec 2023 01:12:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> proposed a very simple solution to this, but I have a multi-step solution using no plugins, <em>without having to perform the same find-replace multiple times in a row:</em></p>
<p dir="auto">Make sure <code>Regular expressions</code> are <strong>ON</strong> in the find/replace form before starting this.</p>
<p dir="auto">The document starts looking like this:</p>
<pre><code>foo
bar

baz
foo
foo

bar
bar
baz
quz

foo
</code></pre>
<ol>
<li>Use the find/replace form to replace <code>^</code> with <code>\x07</code>. <strong>This adds a <code>BEL</code> character (convenient because it does not show up naturally in most text documents) to the beginning of each line.</strong></li>
<li>Make a column selection in the first column of every line of the file, then use the column editor to insert a number (with leading zeros to facilitate sorting). <strong>This numbers the rows, so they can later be put back in order.</strong><br />
<img src="/assets/uploads/files/1702341697514-6e8abd36-ff51-41a8-96d7-7306ab623669-image.png" alt="6e8abd36-ff51-41a8-96d7-7306ab623669-image.png" class=" img-fluid img-markdown" /></li>
<li>Use the find/replace form to replace <code>(?-s)^(\d+)(\x07)(.*)</code> with <code>${3}${2}${1}</code>. <strong>This puts the column numbers after everything else.</strong></li>
<li>Use the menu command <code>Edit-&gt;Line Operations-&gt;Sort Lines Lex. Ascending Ignoring Case</code>. <strong>Now all the lines with the same text are grouped together, and a single regex-replace can get rid of all but the first line with given text.</strong><br />
<img src="/assets/uploads/files/1702342108475-3c2274bc-a772-4b8f-8f5d-2f4f7149f143-image.png" alt="3c2274bc-a772-4b8f-8f5d-2f4f7149f143-image.png" class=" img-fluid img-markdown" /></li>
<li>Find/replace <code>(?-s)^(.+)\x07\d+(?:\R\1\x07\d+)*</code> with <code>~~~~${0}</code>. <strong>This marks the first instance of each line, so that it won’t be deleted later. Note that the <code>~~~~</code> in this example should be replaced with some other text that occurs nowhere in your document.</strong><br />
<img src="/assets/uploads/files/1702342384380-c755e9c0-d0f2-4c5d-bd1c-cb8a5b008180-image.png" alt="c755e9c0-d0f2-4c5d-bd1c-cb8a5b008180-image.png" class=" img-fluid img-markdown" /></li>
<li>Find/replace <code>(?-s)^(?!~~~~).*(\x07\d+)</code> with <code>${1}</code>. <strong>This clears the text but not the line number of any line that does not have the first instance of its text.</strong><br />
<img src="/assets/uploads/files/1702342573454-1d2fdb73-56c6-48f7-a59b-0a41ee2181a1-image.png" alt="1d2fdb73-56c6-48f7-a59b-0a41ee2181a1-image.png" class=" img-fluid img-markdown" /></li>
<li>Find/replace <code>^~~~~</code> with nothing. <strong>This removes the starting marker.</strong></li>
<li>Find/replace <code>(?-s)^(.*)(\x07)(\d+)$</code> with <code>${3}${2}$1</code>. <strong>This brings the line numbers back to the front so that the lines can go back in order.</strong></li>
<li>Use the menu command <code>Edit-&gt;Line Operations-&gt;Sort Lines Lex. Ascending Ignoring Case</code>. <strong>Now all the lines are back in their original order.</strong><br />
<img src="/assets/uploads/files/1702342842862-15e0de09-df0e-4c9a-97b7-0e0314d296dc-image.png" alt="15e0de09-df0e-4c9a-97b7-0e0314d296dc-image.png" class=" img-fluid img-markdown" /></li>
<li>Find/replace <code>^\d+\x07</code> with nothing. <strong>This removes the line numbers and separator.</strong></li>
</ol>
<p dir="auto">Finally, you are left with the original document with the non-first instances of each line’s text replaced with nothing! A lot of steps, but <em>every step is highly scalable and won’t exhibit bad performance on very large files.</em></p>
<pre><code>foo
bar

baz






quz


</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/91150</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91150</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Tue, 12 Dec 2023 01:12:33 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Mon, 11 Dec 2023 11:35:40 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/marcos-miguel" aria-label="Profile: marcos-miguel">@<bdi>marcos-miguel</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/thomas-knoefel" aria-label="Profile: thomas-knoefel">@<bdi>thomas-knoefel</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: coises">@<bdi>coises</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Let’s use a <strong>real</strong> example ! So, we start with this <em>INPUT</em> text, containing a list of English/American <strong>first-names</strong> :</p>
<pre><code class="language-diff">Ted
Mary
Alice
John
Mary
Alice
Peter
Alice
John
Andrew
Ted
Mary
John
Ted
Elisabeth
Andrew
Peter
Peter
Susan
</code></pre>
<p dir="auto">And, <a class="plugin-mentions-user plugin-mentions-a" href="/user/marcos-miguel" aria-label="Profile: marcos-miguel">@<bdi>marcos-miguel</bdi></a>, you would like this <strong>expected</strong> <em>OUTPUT</em> text, wouldn’t you ?</p>
<pre><code class="language-diff">Ted
Mary
Alice
John


Peter


Andrew




Elisabeth



Susan
</code></pre>
<hr />
<p dir="auto">If so, here are the steps for a <strong>regex</strong> solution, which does <em>NOT</em> even need any plugin and does <em>NOT</em> need previous <strong>sorted</strong> data, too !</p>
<ul>
<li>
<p dir="auto">Open your file within N++</p>
</li>
<li>
<p dir="auto">Open the <strong>Replace</strong> dialog ( <strong><code>Ctrl + H</code></strong> )</p>
</li>
<li>
<p dir="auto">First, <strong>untick</strong> all <strong>box</strong> options</p>
</li>
<li>
<p dir="auto">SEARCH <strong><code>(?-is)^((.+)\R(?s:.+?))^\2</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>\1</code></strong></p>
</li>
<li>
<p dir="auto"><strong>Check</strong> the <strong><code>Wrap around</code></strong> option ( <em>IMPORTANT</em> )</p>
</li>
<li>
<p dir="auto">Select the <strong><code>Regular expression</code></strong> search <strong>mode</strong></p>
</li>
<li>
<p dir="auto">Click, <strong>repeatedly</strong>, on the <strong><code>Replace All</code></strong> button <em>OR</em> on the <strong><code>Replace</code></strong> button, until you get :</p>
</li>
</ul>
<p dir="auto">The message <strong><code>Replace: no occurrence was found</code></strong> OR the message <strong><code>Replace All: 0 occurrences were replaced in entire file</code></strong></p>
<hr />
<p dir="auto">A <strong>second</strong> and <strong>equivalent</strong> solution would be :</p>
<ul>
<li>
<p dir="auto">Open your file within N++</p>
</li>
<li>
<p dir="auto">Open the <strong>Replace</strong> dialog ( <strong><code>Ctrl + H</code></strong> )</p>
</li>
<li>
<p dir="auto">First, <strong>untick</strong> all <strong>box</strong> options</p>
</li>
<li>
<p dir="auto">SEARCH <strong><code>(?-is)^(.+)\R(?s:.+?)\K^\1</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
<li>
<p dir="auto"><strong>Check</strong> the <strong><code>Wrap around</code></strong> option ( <em>IMPORTANT</em> )</p>
</li>
<li>
<p dir="auto">Select the <strong><code>Regular expression</code></strong> search <strong>mode</strong></p>
</li>
<li>
<p dir="auto">Click <strong>repeatedly</strong> on the <strong><code>Replace All</code></strong> button ( Do <em>NOT</em> use the <strong><code>Replace</code></strong> button ), until you get the message <strong><code>Replace All: 0 occurrences were replaced in entire file</code></strong></p>
</li>
</ul>
<hr />
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">If you use the <strong>first</strong> solution, on a file containing a <strong>huge</strong> number of lines and where <strong>two duplicate</strong> lines are possibly separated by a <strong>great</strong> amount of other lines, the search regex may <strong>not</strong> work properly. In this case, I advice you to prefer the <strong>last</strong> solution which should work nicely in <strong>most</strong> of the cases !</p>
</li>
<li>
<p dir="auto">When using the <strong>second</strong> solution, remember  to <em>NEVER</em> use the <strong><code>Replace</code></strong> button but <em>ONLY</em> the <strong><code>Replace All</code></strong> one, because of the <strong><code>\K</code></strong> syntax in the <strong>search</strong> regex !</p>
</li>
</ul>
<p dir="auto">Best Regards</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91124</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91124</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Mon, 11 Dec 2023 11:35:40 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Mon, 11 Dec 2023 10:31:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/marcos-miguel" aria-label="Profile: Marcos-Miguel">@<bdi>Marcos-Miguel</bdi></a> said in <a href="/post/91111">How to remove ALL the duplicates WITHOUT deleting the empty lines?</a>:</p>
<blockquote>
<p dir="auto">What I need is a formula that keeps just the first number 1 and delete all others.</p>
</blockquote>
<p dir="auto">Hi Miguel, i don’t have a regex solution which works this flexibel to delete all the following duplicates. But maybe other Regex experts can.</p>
<p dir="auto">But if you have the possibility to install Plugins you can simply do it with <a href="https://github.com/daddel80/notepadpp-multireplace?tab=readme-ov-file#multireplace-for-notepad" rel="nofollow ugc">MultiReplace</a> Plugin</p>
<ol>
<li>
<p dir="auto">Activate Checkbox “<code>Use Variables</code>”</p>
</li>
<li>
<p dir="auto">Add into the list -&gt;</p>
</li>
</ol>
<p dir="auto">Find what: <code>1</code><br />
Replace with: <code>cond(CNT &gt; 1, '')</code></p>
<p dir="auto">Find what: <code>2</code><br />
Replace with: <code>cond(CNT &gt; 1, '')</code></p>
<p dir="auto">Find what: <code>3</code><br />
Replace with: <code>cond(CNT &gt; 1, '')</code></p>
<ol start="3">
<li>start <code>Replace All</code> with activated "<code>Use List"</code> Checkbox</li>
</ol>
<p dir="auto">PS: The next MultiReplace version 2.2.0.9 is in development, which will offer more flexibility in “Use Variables”, even for automatic duplicate detection. This solution can then be described within a single-line expression, apart from the expected duplicate values.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91122</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91122</guid><dc:creator><![CDATA[Thomas Knoefel]]></dc:creator><pubDate>Mon, 11 Dec 2023 10:31:18 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Sun, 10 Dec 2023 17:51:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/marcos-miguel" aria-label="Profile: Marcos-Miguel">@<bdi>Marcos-Miguel</bdi></a> said in <a href="/post/91115">How to remove ALL the duplicates WITHOUT deleting the empty lines?</a>:</p>
<blockquote>
<p dir="auto">Very polite of you.</p>
</blockquote>
<p dir="auto">I was polite in my first response.<br />
I probably should have redirected you to the FAQ section (which you should have read anyway before posting on any site new to you) where there is detailed instructions on how to ask such a question as yours.</p>
<p dir="auto">And someone else was polite to you, but you ignored their request (“Can you provide an example of what your file structure looks like and how it should look at the end?”)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91116</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91116</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sun, 10 Dec 2023 17:51:58 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Sun, 10 Dec 2023 17:47:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> Yes and thank you for your kind words. Very polite of you.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91115</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91115</guid><dc:creator><![CDATA[Marcos Miguel]]></dc:creator><pubDate>Sun, 10 Dec 2023 17:47:07 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Sun, 10 Dec 2023 17:07:38 GMT]]></title><description><![CDATA[<p dir="auto">PLEASE just try to ask a decent question.</p>
<p dir="auto">Supposing your BEORE data is:</p>
<pre><code>1
1
1
2
2
3
</code></pre>
<p dir="auto">and your AFTER data that you want looks like this:</p>
<pre><code>1


2

3
</code></pre>
<p dir="auto">???</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91113</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91113</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sun, 10 Dec 2023 17:07:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Sun, 10 Dec 2023 16:30:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thomas-knoefel" aria-label="Profile: Thomas-Knoefel">@<bdi>Thomas-Knoefel</bdi></a></p>
<p dir="auto">let’s say I have the following sequence<br />
1<br />
1<br />
1<br />
2<br />
2<br />
3</p>
<p dir="auto">If I run the following formula to remove the duplicates</p>
<p dir="auto">(.+)$\R+\K\1</p>
<p dir="auto">then this is what I get</p>
<p dir="auto">1</p>
<p dir="auto">1<br />
2</p>
<p dir="auto">3<br />
1</p>
<p dir="auto">What I need is a formula that keeps just the first number 1 and delete all others.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91111</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91111</guid><dc:creator><![CDATA[Marcos Miguel]]></dc:creator><pubDate>Sun, 10 Dec 2023 16:30:32 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Sun, 10 Dec 2023 11:14:00 GMT]]></title><description><![CDATA[<p dir="auto">I’d guess that OP wants to not remove duplicate lines, but rather erase their contents, e.g. make them have nothing but a line-ending on them?</p>
<p dir="auto">But really, yea, OP needs to provide more detail on the needed task.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91097</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91097</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sun, 10 Dec 2023 11:14:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove ALL the duplicates WITHOUT deleting the empty lines? on Sun, 10 Dec 2023 11:14:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/marcos-miguel" aria-label="Profile: Marcos-Miguel">@<bdi>Marcos-Miguel</bdi></a><br />
Can you provide an example of what your file structure looks like and how it should look at the end? This will make it easier to understand.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/91096</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/91096</guid><dc:creator><![CDATA[Thomas Knoefel]]></dc:creator><pubDate>Sun, 10 Dec 2023 11:14:14 GMT</pubDate></item></channel></rss>