<?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[Search and replace between 2 files]]></title><description><![CDATA[<p dir="auto">Dear experts,</p>
<p dir="auto">I have two different files and I have to search and replace strings in this way:</p>
<p dir="auto">in the file A, I have to check if in the row there is the string [NO_CODE].<br />
Then, in the same row, I have to select the text between ; and [<br />
(for example the selection will be 5384578)<br />
The text may be variable lenght</p>
<p dir="auto">Sample file A<br />
XXX_020_G30;00;M9990940382;00;3;<br />
XXX_020_G30;00;5384578 [NO_CODE];00;3;<br />
XXX_020_G30;00;1214_020_341;00;2;<br />
XXX_020_G30;00;M9990940381;00;8;<br />
XXX_020_G30;00;1214_048_G37;00;1;</p>
<p dir="auto">In the file B, I have to search the string 5384578. Then in the row found, I have to select the string before ; copy and substitute 5384578 [NO_CODE] in file A. If, in the file B there is not the matching string, return to file A and skip to the next row.</p>
<p dir="auto">Sample file B<br />
M0100940001;6012602;<br />
M0100940002;6012606;<br />
M0100940003;6012605;<br />
M0220580002;5384578;<br />
M0220580004;5940029;<br />
M0220580005;5940030;<br />
M0220580007;5940111;<br />
M0220780001;5952013;</p>
<p dir="auto">Final file will be:</p>
<p dir="auto">XXX_020_G30;00;M9990940382;00;3;<br />
XXX_020_G30;00;M0220580002;00;3;<br />
XXX_020_G30;00;1214_020_341;00;2;<br />
XXX_020_G30;00;M9990940381;00;8;<br />
XXX_020_G30;00;1214_048_G37;00;1;</p>
<p dir="auto">Anyone can help me?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20052/search-and-replace-between-2-files</link><generator>RSS for Node</generator><lastBuildDate>Wed, 10 Jun 2026 05:32:53 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20052.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 25 Sep 2020 06:43:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Search and replace between 2 files on Wed, 30 Sep 2020 11:39:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/makwana-prahlad" aria-label="Profile: Makwana-Prahlad">@<bdi>Makwana-Prahlad</bdi></a> said in <a href="/post/58058">Search and replace between 2 files</a>:</p>
<blockquote>
<p dir="auto">PeopleSleptWith</p>
</blockquote>
<p dir="auto">???</p>
<p dir="auto">I think it is time for “banning” this individual.</p>
<p dir="auto">Grounds:  He pollutes threads with posts with useless and unrelated information which will only make any future readers seeking a solution to the problem originally posed confused.</p>
<p dir="auto">Need more evidence:  Look at his previous postings.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58062</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58062</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 30 Sep 2020 11:39:54 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace between 2 files on Wed, 30 Sep 2020 03:43:58 GMT]]></title><description><![CDATA[<p dir="auto">Hello,<a class="plugin-mentions-user plugin-mentions-a" href="/user/enzo-turatti" aria-label="Profile: Enzo-Turatti">@<bdi>Enzo-Turatti</bdi></a><br />
Please follow this Step,To Search and replace between 2 files</p>
<p dir="auto">The Find in <strong>Files tab</strong> (Search &gt; Find in Files or <strong>Ctrl+Shift+F</strong>) allows you to search and replace in multiple files with one action.</p>
<p dir="auto"><strong>Step 1:</strong> press Ctrl+F and then from the Find in Files tab options.<br />
<strong>Step 2:</strong> Put the string in the regex format of the Find What:<br />
<em><em>^.</em> (PeopleSleptWith).*$</em>*<br />
The string will go between the <strong>“()”</strong> parenthesis just as shown above in #1<br />
<strong>Step 3:</strong> Put the 5 spaces and then the Replace with: PeopleSleptWith 7 string<br />
<strong>Step 4:</strong> Put the Filters: as <em>.</em> or *.txt or whatever you are replacing file type wise<br />
<strong>Step 5:</strong> Put the Directory: where you want it to be<br />
<strong>Step 6:</strong> Check the Regular expression option<br />
<strong>Step 7:</strong> Select Replace in Files then Check the file(s) and all should be correct now</p>
<p dir="auto">I hope this information will be useful.<br />
Thank you.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58058</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58058</guid><dc:creator><![CDATA[Makwana Prahlad]]></dc:creator><pubDate>Wed, 30 Sep 2020 03:43:58 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace between 2 files on Mon, 28 Sep 2020 10:32:11 GMT]]></title><description><![CDATA[<p dir="auto">Thank you very much.<br />
This week I should have time to test your suggestions.</p>
<p dir="auto">Best regards!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58006</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58006</guid><dc:creator><![CDATA[Enzo Turatti]]></dc:creator><pubDate>Mon, 28 Sep 2020 10:32:11 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace between 2 files on Fri, 25 Sep 2020 18:37:06 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/enzo-turatti" aria-label="Profile: enzo-turatti">@<bdi>enzo-turatti</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a> and <strong>All</strong>,</p>
<p dir="auto"><strong>Alan</strong>, I’ve just changed your line :</p>
<pre><code class="language-py">editor.rereplace(r'(?s-i)([^;]+)\x20[NO_CODE](?=.+===.+^(.+?);\1;)|^===.+', r'\2')~~~
</code></pre>
<p dir="auto">as</p>
<pre><code class="language-py">editor.rereplace(r'(?s-i)([^;]+)\x20\\[NO_CODE\\](?=.+===.+^(.+?);\1;)|^===.+', r'\2')
</code></pre>
<p dir="auto">n order that the regex <strong>works</strong> !! Seemingly it’s a problem with the <strong>NoddBB</strong>’s forum ! In order to show <strong><code>\\[</code></strong> you must write <strong><code>\\\[</code></strong></p>
<hr />
<p dir="auto">For <strong>test</strong>, I used this example :</p>
<pre><code class="language-diff">XXX_020_G30;00;M9990940382;00;3;
XXX_020_G30;00;5384578 [NO_CODE];00;3;    // Line to be MODIFIED
XXX_020_G30;00;1214_020_341;00;2;
XXX_020_G30;00;M9990940381;00;8;
XXX_020_G30;00;1214_048_G37;00;1;
.....
XXX_020_G30;00;M9990940382;00;3;    \
XXX_020_G30;00;1214_020_341;00;2;   |     // repeated 66,433 times 
XXX_020_G30;00;M9990940381;00;8;    |
XXX_020_G30;00;1214_048_G37;00;1;   /
.....
XXX_020_G30;00;M9990940382;00;3;
XXX_020_G30;00;1214_020_341;00;2;         // ONCE more
XXX_020_G30;00;M9990940381;00;8;
XXX_020_G30;00;1214_048_G37;00;1;
======
M0100940001;6012602;
M0100940002;6012606;
M0100940003;6012605;
M0220580002;5384578;
M0220580004;5940029;
M0220580005;5940030;
M0220580007;5940111;
M0220780001;5952013;
</code></pre>
<p dir="auto">This give a total of <strong><code>5 + 4 x 66434 + 9</code></strong> = <strong><code>265,750</code></strong> lines !</p>
<ul>
<li>
<p dir="auto">Running, either the <strong>regex</strong> from within <strong>N++</strong> or the <strong>one</strong>-line <strong>Python</strong> script, above, it’s <em>OK</em> for <strong>both</strong> but the script is <strong>faxter</strong> ( <strong><code>13s</code></strong> instead of <strong><code>20s</code></strong> for the <strong>regex</strong>, on my <strong>old</strong> Windows <strong><code>XP SP3</code></strong>  machine ! )</p>
</li>
<li>
<p dir="auto">Unfortunately, when adding <strong><code>48</code></strong> lines <strong>only</strong> ( 12 blocks of four lines ) for a total of <strong><code>265,798</code></strong> lines :</p>
<ul>
<li>
<p dir="auto">The regex <strong>fails</strong> and <strong>deletes</strong> all the contents, leaving <strong>two</strong> lines only !</p>
</li>
<li>
<p dir="auto">The <strong>python</strong> script also <strong>fails</strong> to do the replacement and reports this <strong>error</strong> :</p>
</li>
</ul>
</li>
</ul>
<pre><code class="language-z">Traceback (most recent call last):
  File "D:\@@\785\plugins\Config\PythonScript\scripts\Test_Alan.py", line 2, in &lt;module&gt;
    editor.rereplace(r'(?s-i)([^;]+)\x20\\[NO_CODE\\](?=.+===.+^(.+?);\1;)|^===.+', r'\2')
RuntimeError: The complexity of matching the regular expression exceeded predefined bounds.  Try refactoring the regular expression to make each choice made by the state machine unambiguous.  This exception is thrown to prevent "eternal" matches that take an indefinite period time to locate.
</code></pre>
<p dir="auto"><strong>Remarks</strong> :</p>
<ul>
<li>
<p dir="auto">The <strong>Python</strong>’s script behaviour is <strong>nicer</strong> because, in case of problem, it does <strong>not</strong> change the file at all and just outputs an <strong>error</strong> :-))</p>
</li>
<li>
<p dir="auto">The Python script seems <strong>significantly</strong> faster than the native N++ <strong>regex engine</strong> !</p>
</li>
<li>
<p dir="auto">Finally, as the lines of the <a class="plugin-mentions-user plugin-mentions-a" href="/user/enzo-turatti" aria-label="Profile: enzo-turatti">@<bdi>enzo-turatti</bdi></a>’s example are rather <strong>small</strong>, both the <strong>regex</strong> S/R or the equivalent <strong>Python</strong> script seem to work with a <strong><code>9 Mb</code></strong> file ! However, I just created a case with <strong>one</strong> concordance, only ! As always, working with <strong>real</strong> data will put an end to our <strong>questions</strong> !</p>
</li>
</ul>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/57930</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/57930</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Fri, 25 Sep 2020 18:37:06 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace between 2 files on Fri, 25 Sep 2020 13:16:30 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> said in <a href="/post/57920">Search and replace between 2 files</a>:</p>
<blockquote>
<p dir="auto">As said above, the behaviour of this regex highly depends on the size of files ! Il may fail and even end with a null file C !</p>
</blockquote>
<p dir="auto">This failure comes up a lot in such solutions.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> Have you ever switched to the following (as an experiment) when such a failure has occurred?:</p>
<p dir="auto">In Pythonscript console, do the following:</p>
<p dir="auto"><code>editor.rereplace(r'</code> search_expr <code>', r'</code> replace_expr <code>')</code></p>
<p dir="auto">Specifically for the case above, it would be:</p>
<p dir="auto"><code>editor.rereplace(r'(?s-i)([^;]+) [NO_CODE](?=.+===.+^(.+?);\1;)|^===.+', r'\2')</code></p>
<p dir="auto">I’m just wondering if this technique would work when the native N++ technique fails.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/57923</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/57923</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 25 Sep 2020 13:16:30 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace between 2 files on Fri, 25 Sep 2020 11:24:42 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/enzo-turatti" aria-label="Profile: enzo-turatti">@<bdi>enzo-turatti</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Here is a <strong>regex</strong> solution which works <em>ONLY IF</em> the number of lines of file <strong>A</strong> and <strong>B</strong> are <strong>not too</strong> important !</p>
<ul>
<li>
<p dir="auto">First copy the contents of file <strong>A</strong> in a file <strong>C</strong></p>
</li>
<li>
<p dir="auto">Add a <strong>dummy</strong> line of, at least, <strong>three</strong> <strong><code>=</code></strong> signs</p>
</li>
<li>
<p dir="auto">Append the contents of file <strong>B</strong> under the line <strong><code>======</code></strong></p>
</li>
</ul>
<p dir="auto">=&gt; So, the contents of file <strong>C</strong> should be :</p>
<pre><code class="language-diff">XXX_020_G30;00;M9990940382;00;3;
XXX_020_G30;00;5384578 [NO_CODE];00;3;
XXX_020_G30;00;1214_020_341;00;2;
XXX_020_G30;00;M9990940381;00;8;
XXX_020_G30;00;1214_048_G37;00;1;
======
M0100940001;6012602;
M0100940002;6012606;
M0100940003;6012605;
M0220580002;5384578;
M0220580004;5940029;
M0220580005;5940030;
M0220580007;5940111;
M0220780001;5952013;
</code></pre>
<ul>
<li>
<p dir="auto">Run the following regex S/R, against file <strong>C</strong> :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s-i)([^;]+) \[NO_CODE\](?=.+===.+^(.+?);\1;)|^===.+</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>\2</code></strong></p>
</li>
</ul>
</li>
</ul>
<p dir="auto">You should obtain your <strong>expected</strong> text :</p>
<pre><code class="language-diff">XXX_020_G30;00;M9990940382;00;3;
XXX_020_G30;00;M0220580002;00;3;
XXX_020_G30;00;1214_020_341;00;2;
XXX_020_G30;00;M9990940381;00;8;
XXX_020_G30;00;1214_048_G37;00;1;
</code></pre>
<hr />
<p dir="auto">As said above, the behaviour of this regex <strong>highly</strong> depends on the <strong>size</strong> of files ! Il may <strong>fail</strong> and even end with a <strong>null</strong> file <strong>C</strong> !</p>
<p dir="auto">In this case, we’ll have to find out an <strong>other</strong> way, which probably will use <strong>sorting</strong> !</p>
<p dir="auto">See you later,</p>
<p dir="auto">Best regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/57920</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/57920</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Fri, 25 Sep 2020 11:24:42 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace between 2 files on Fri, 25 Sep 2020 10:42:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/enzo-turatti" aria-label="Profile: Enzo-Turatti">@<bdi>Enzo-Turatti</bdi></a> said in <a href="/post/57913">Search and replace between 2 files</a>:</p>
<blockquote>
<p dir="auto">Dear experts,<br />
I have two different files and I have to search and replace strings in this way</p>
</blockquote>
<p dir="auto">I believe it is possible, however it will require a few steps. In broad terms:</p>
<ol>
<li>Bring the “key” to the front of the lines in both files. The two files could then be combined and sorted which would put any possible pairs together.</li>
<li>With each pair adjust the line from file a changing the character sequence with what the secondary line has.</li>
<li>Remove all of the lines from file b and remove the key from the front of the line.</li>
</ol>
<p dir="auto">Sounds relatively straight forward. It only remains to be seen if in reality it works that easily.<br />
Question  is the line order in file a important as that can be catered for, but it does complicate it some more.<br />
Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/57918</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/57918</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Fri, 25 Sep 2020 10:42:19 GMT</pubDate></item></channel></rss>