<?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[Append third row of text to a find replace?]]></title><description><![CDATA[<p dir="auto">I have 1k+ files that I need to find foo in and make it foo&amp;3rdrow. Least complex way to make this happen without hand massaging each file? Thanks!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/15204/append-third-row-of-text-to-a-find-replace</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 16:37:58 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/15204.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 04 Feb 2018 17:44:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Append third row of text to a find replace? on Tue, 06 Feb 2018 17:17:11 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/matthew-suhajda" aria-label="Profile: Matthew-suhajda">@<bdi>Matthew-suhajda</bdi></a>, and <strong>All</strong>,</p>
<p dir="auto">Pleased to hear that it worked <strong>fine</strong> ! Just for information :</p>
<p dir="auto">Regarding the <strong>first</strong> S/R :</p>
<p dir="auto">SEARCH <strong><code>(?-s)^(?:.*\R){2}(.+)(?s).+</code></strong></p>
<p dir="auto">REPLACE <strong><code>$0\r\n\1</code></strong></p>
<ul>
<li>
<p dir="auto">The <strong>modifier</strong> <strong><code>(?-s)</code></strong> means that, further <strong>dots</strong> will match <strong>any single</strong> character, only</p>
</li>
<li>
<p dir="auto">Then, the part <strong><code>^(?:.*\R){2}</code></strong> looks for the <strong>first two</strong> lines, with their <strong>EOL</strong> chars, in a <strong>non capturing</strong> group</p>
</li>
<li>
<p dir="auto">Now, the part <strong><code>(.+)</code></strong> stores, as group <strong>1</strong>, the <strong>next <code>3rd</code></strong> line, <strong>without</strong> its <strong>End of Line</strong> characters</p>
</li>
<li>
<p dir="auto">Finally, the <strong><code>(?s).+</code></strong> syntax catches <strong>all remaining</strong> text from <strong>End of Line</strong> characters  of line <strong>3</strong></p>
</li>
<li>
<p dir="auto">In replacement, due to the <strong><code>$0</code></strong> syntax, it re-writes, first, the <strong>entire matched</strong> text ( = file <strong>contents</strong> ), followed with a <strong>Windows</strong> line break ( <strong><code>\r\n</code></strong> ) and, finally, with the group <strong>1</strong> ( = The <strong><code>3rd</code></strong> line = <strong>time stamp</strong> )</p>
</li>
</ul>
<hr />
<p dir="auto">Regarding the <strong>second</strong> S/R :</p>
<p dir="auto">SEARCH <strong><code>(?i)foo(?s)(?=.*\R(.+)\z)|(?-s)\R.+\z</code></strong></p>
<p dir="auto">REPLACE <strong><code>?1foo\x20\1</code></strong></p>
<ul>
<li>
<p dir="auto">The <strong>searched</strong> regex is made of <strong>two alternatives</strong>, separated by the <strong>alternation</strong> special character <strong><code>|</code></strong> :</p>
<ul>
<li>
<p dir="auto"><strong><code>(?i)foo(?s)(?=.*\R(.+)\z)</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-s)\R.+\z</code></strong></p>
</li>
</ul>
</li>
<li>
<p dir="auto">In the <strong>first</strong> alternative, the part <strong><code>(?i)foo</code></strong> tries, first, to match the <strong>foo</strong> word, in <strong>any</strong> case</p>
</li>
<li>
<p dir="auto">Then, the <strong><code>(?s)(?=.*\R(.+)\z)</code></strong> syntax represents an  <strong>always true</strong> look-ahead, <strong><code>(?=......)</code></strong>, which matches <strong>all</strong> text after the <strong>foo</strong> word, till the <strong>second to the last</strong> line ( <strong><code>.*\R</code></strong> ), and the <strong>last</strong> ( or <strong><code>3rd</code></strong> ) line, <strong>without</strong> any line-break ( <strong><code>(.+)\z</code></strong> ), which is stored as group <strong>1</strong></p>
</li>
<li>
<p dir="auto">Near the <strong>end</strong> of each file, the <strong>second</strong> alternative, <strong><code>(?-s)\R.+\z</code></strong>, looks for the <strong>very last</strong> ( or <strong><code>3rd</code></strong> ) line contents, till the <strong>very end</strong> of each file ( <strong><code>\z</code></strong> )</p>
</li>
<li>
<p dir="auto">In replacement, the <strong><code>?1foo\x20\1</code></strong> syntax means :</p>
<ul>
<li>
<p dir="auto">If <strong>group 1</strong> exists, it rewrites the <strong>entire</strong> matched string <strong>foo</strong>, followed with a <strong>space</strong> character and the <strong>time stamp</strong> ( <strong>last</strong> ) line ( <strong><code>\1</code></strong> )</p>
</li>
<li>
<p dir="auto">If group <strong>1</strong> does <strong>not</strong> exist ( case of the <strong>second</strong> alternative ), the <strong>very last</strong> line, temporarily <strong>added</strong>, is then, simply, <strong>deleted</strong>, as <strong>no</strong> <em>ELSE</em> part is present in the <strong>conditional</strong> replacement <strong><code>?1.....</code></strong> !</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30070</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30070</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 06 Feb 2018 17:17:11 GMT</pubDate></item><item><title><![CDATA[Reply to Append third row of text to a find replace? on Mon, 05 Feb 2018 21:46:36 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:</p>
<blockquote>
<p dir="auto">?1foo\x20\1</p>
</blockquote>
<p dir="auto">Exquisite. Worked perfectly. Hopefully this is the only time I’ll need to do something like this, but I will totally ask for more direction in the future if it comes up again.  There’s always a new puzzle when dealing with shitty data! lol</p>
<p dir="auto">Thank you so very much.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30035</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30035</guid><dc:creator><![CDATA[Matthew Suhajda]]></dc:creator><pubDate>Mon, 05 Feb 2018 21:46:36 GMT</pubDate></item><item><title><![CDATA[Reply to Append third row of text to a find replace? on Mon, 05 Feb 2018 21:00:11 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/matthew-suhajda" aria-label="Profile: Matthew-suhajda">@<bdi>Matthew-suhajda</bdi></a>, and <strong>All</strong>,</p>
<p dir="auto">Well ! My idea consists in <strong>three</strong> steps :</p>
<ul>
<li>
<p dir="auto">Firstly, copy the <strong>time stamp</strong> <strong><code>3rd</code></strong> line ( which I suppose to be <strong>different</strong> for each file !) at the <strong>very end</strong> of <strong>each</strong> file scanned, after a <strong>pure blank</strong> line ! this <strong>new</strong> line won’t be followed by any <strong>line-break</strong></p>
</li>
<li>
<p dir="auto">Secondly, search for <strong>any</strong> occurrence of the <strong>foo</strong> expression, with a <strong>look-ahead</strong> feature ( <strong>always</strong> true ) which stores the the <strong>very last</strong> line ( The <strong>time stamp</strong> line ) , added during the <strong>previous</strong> S/R step, as <strong>group 1</strong></p>
</li>
<li>
<p dir="auto">Thirdly, delete, in <strong>each</strong> file scanned, the <strong>very last</strong> line, <strong>temporarily</strong> added</p>
</li>
</ul>
<p dir="auto">The <strong>first</strong> point is realized with a <strong>first</strong> regex <strong>S/R</strong>. The <strong>second</strong> and <strong>third</strong> ones are done, all together, by a <strong>second</strong> regex <strong>S/R</strong></p>
<p dir="auto">Note that it’s necessary to copy the <strong>time stamp</strong> line at the <strong>very end</strong>, because, once the regex engine position is after <strong>Line 3</strong>, looking for some <strong>foo</strong> occurrences, it <strong>cannot</strong> remember that <strong>specific</strong> line, because it’s not part, anymore, of the <strong>later</strong> matches !</p>
<hr />
<p dir="auto">So, let’s imagine the text below, with the <strong>time stamp</strong> in <strong><code>line 3</code></strong> and the <strong><code>foo</code></strong> word, in lines <strong><code>2</code></strong>, <strong><code>6</code></strong>, <strong><code>8</code></strong> and <strong><code>10</code></strong> :</p>
<pre><code class="language-diff">This is a small
example foo of
1/1/2008 14:53:36
text for testing
the Matthew's goal !
foo It doesn't
mean anything
and foo it's created
to test the
search/replacement foo
That's the end.
</code></pre>
<p dir="auto">Then, the <strong>first</strong> regex S/R :</p>
<p dir="auto">SEARCH <strong><code>(?-s)^(?:.*\R){2}(.+)(?s).+</code></strong></p>
<p dir="auto">REPLACE <strong><code>$0\r\n\1</code></strong></p>
<p dir="auto">would give the following text, with a <strong>last</strong> line ( the <strong><code>3rd</code></strong> ) <strong>added</strong> :</p>
<pre><code class="language-diff">This is a small
example foo of
1/1/2008 14:53:36
text for testing
the Matthew's goal !
foo It doesn't
mean anything
and foo it's created
to test the
search/replacement foo
That's the end.

1/1/2008 14:53:36
</code></pre>
<p dir="auto">Now, the <strong>second</strong> regex S/R :</p>
<p dir="auto">SEARCH <strong><code>(?i)foo(?s)(?=.*\R(.+)\z)|(?-s)\R.+\z</code></strong></p>
<p dir="auto">REPLACE <strong><code>?1foo\x20\1</code></strong></p>
<p dir="auto">give the <strong>expected</strong> text, below :</p>
<pre><code class="language-diff">This is a small
example foo 1/1/2008 14:53:36 of
1/1/2008 14:53:36
text for testing
the Matthew's goal !
foo 1/1/2008 14:53:36 It doesn't
mean anything
and foo 1/1/2008 14:53:36 it's created
to test the
search/replacement foo 1/1/2008 14:53:36
That's the end.
</code></pre>
<p dir="auto">I supposed that the search is <strong>insensitive</strong> to the case, so words <strong><code>FOO</code></strong>, <strong><code>Foo</code></strong>,… would match. If you prefer a <strong>sensitive</strong> search, just change the <strong>first</strong> regex part <strong><code>(?i)</code></strong> with the <strong><code>(?-i)</code></strong> syntax</p>
<hr />
<p dir="auto">Practically, <strong>Matthew</strong>, follow these <strong>few</strong> steps :</p>
<ul>
<li>
<p dir="auto">First, <strong>BACKUP</strong> all the files, concerned with these <strong>S/R</strong> ( <strong><code>IMPORTANT</code></strong> )</p>
</li>
<li>
<p dir="auto">Start Notepad ++ and open the <strong>Find in Files</strong> dialog</p>
</li>
<li>
<p dir="auto">Type in <strong><code>(?-s)^(?:.*\R){2}(.+)(?s).+</code></strong> , in the <strong>Find what:</strong> zone</p>
</li>
<li>
<p dir="auto">Type in <strong><code>$0\r\n\1</code></strong> , in the <strong>Replace with:</strong> zone</p>
</li>
<li>
<p dir="auto">Enter the right <strong>extension</strong> of your files ( for instance <strong><code>*.txt</code></strong>, <strong><code>*.html</code></strong>, … ), in the <strong>Filters :</strong> zone</p>
</li>
<li>
<p dir="auto">Add the <strong><code>full pathname</code></strong> of the folder, containing <strong>all</strong> your files, in the <strong>Directory :</strong> zone</p>
</li>
<li>
<p dir="auto">Select the <strong>Regular expression</strong> search mode ( IMPORTANT )</p>
</li>
<li>
<p dir="auto">Click on the <strong>Replace in Files</strong> button</p>
</li>
<li>
<p dir="auto">Click on the <strong>OK</strong> button, of the confirmation dialog</p>
</li>
</ul>
<p dir="auto">At that time, <strong>all</strong> the files scanned should have a <strong>new</strong> line, at their end, <strong>identical</strong> to their <strong><code>3rd</code></strong> line ! Now :</p>
<ul>
<li>
<p dir="auto">Change the <strong>Find what:</strong> zone with the regex <strong><code>(?i)foo(?s)(?=.*\R(.+)\z)|(?-s)\R.+\z</code></strong></p>
</li>
<li>
<p dir="auto">Change the <strong>Replace with:</strong> zone with the regex <strong><code>?1foo\x20\1</code></strong></p>
</li>
<li>
<p dir="auto">Click, again, on the <strong>Replace in Files</strong> button</p>
</li>
<li>
<p dir="auto">Click on the <strong>OK</strong> button, of the confirmation dialog</p>
</li>
</ul>
<p dir="auto">Et voilà ! <strong>any</strong> occurrence of <strong><code>foo</code></strong>, in <strong>each</strong> scanned file, should be followed, after a <strong>space</strong> separator, with the appropriate <strong>time stamp</strong> of <strong>each</strong> file ;-))</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S.</strong> :</p>
<p dir="auto">If you want to, I’ll give you, next time, some <strong>explanations</strong> about these <strong>regexes</strong> !!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30033</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30033</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Mon, 05 Feb 2018 21:00:11 GMT</pubDate></item><item><title><![CDATA[Reply to Append third row of text to a find replace? on Mon, 05 Feb 2018 19:51:24 GMT]]></title><description><![CDATA[<p dir="auto">Note: Pasted as an image because of the stupid spam filter!!  :-D</p>
<p dir="auto"><img src="https://i.imgur.com/UWeJnWe.png" alt="Imgur" class=" img-fluid img-markdown" /><br />
<img src="https://i.imgur.com/7HPMa8E.png" alt="Imgur" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/30031</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30031</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Mon, 05 Feb 2018 19:51:24 GMT</pubDate></item><item><title><![CDATA[Reply to Append third row of text to a find replace? on Mon, 05 Feb 2018 19:19:00 GMT]]></title><description><![CDATA[<p dir="auto">A space between would be perfect.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30026</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30026</guid><dc:creator><![CDATA[Matthew Suhajda]]></dc:creator><pubDate>Mon, 05 Feb 2018 19:19:00 GMT</pubDate></item><item><title><![CDATA[Reply to Append third row of text to a find replace? on Mon, 05 Feb 2018 19:10:03 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/matthew-suhajda" aria-label="Profile: Matthew-suhajda">@<bdi>Matthew-suhajda</bdi></a>,</p>
<p dir="auto">OK for the <strong>time stamp</strong>, in line <strong><code>3</code></strong> of your files, but you didn’t add what text you expect to, <strong>after</strong> replacement !</p>
<p dir="auto">I mean : Is the <strong><code>foo</code></strong> generic expression, located, in your example, in lines <strong><code>4</code></strong>, <strong><code>6</code></strong> and <strong><code>8</code></strong>, should be <strong>replaced</strong> with :</p>
<ul>
<li>
<p dir="auto"><strong>A</strong> : <strong><code>foo&amp;1/1/2008 14:53:36</code></strong> , with a literal <strong><code>&amp;</code></strong> between ?</p>
</li>
<li>
<p dir="auto"><strong>B</strong> : <strong><code>foo1/1/2008 14:53:36</code></strong> , simply attached ?</p>
</li>
<li>
<p dir="auto"><strong>C</strong> : <strong><code>foo 1/1/2008 14:53:36</code></strong>, with a <strong><code>space</code></strong> separator ?</p>
</li>
<li>
<p dir="auto"><strong>D</strong> :  <strong><code>Other Case</code></strong> ?</p>
</li>
</ul>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30025</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30025</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Mon, 05 Feb 2018 19:10:03 GMT</pubDate></item><item><title><![CDATA[Reply to Append third row of text to a find replace? on Mon, 05 Feb 2018 16:25:38 GMT]]></title><description><![CDATA[<p dir="auto">All 1k files have a date and time stamp at line 3. I need to append that stamp to several places in each file before proceeding to clean up the rest of the data and combine all the files. So more like</p>
<p dir="auto">Line 1<br />
Line 2<br />
Line 3 1/1/2008 14:53:36<br />
Line 4                   foo<br />
Line 5 dsafoj<br />
Line 6 adsaf foo<br />
Line 7<br />
Line 8                      12341234         foo sdfsd</p>
<p dir="auto">I think your example has it correct, but hopefully the above illustrates the case a tad better.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30021</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30021</guid><dc:creator><![CDATA[Matthew Suhajda]]></dc:creator><pubDate>Mon, 05 Feb 2018 16:25:38 GMT</pubDate></item><item><title><![CDATA[Reply to Append third row of text to a find replace? on Sun, 04 Feb 2018 20:51:21 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/matthew-suhajda" aria-label="Profile: Matthew-suhajda">@<bdi>Matthew-suhajda</bdi></a>,</p>
<p dir="auto">I’m trying to <strong>guess</strong> what you want, because a <strong>literal</strong> example would be welcomed !</p>
<p dir="auto">For instance, from the <strong>initial</strong> text, below :</p>
<pre><code class="language-diff">Line foo 1
Line 2
Line 3
Line 4
foo Line 5 
Line 6
Line 7 foo
</code></pre>
<p dir="auto">are you expecting the <strong>following</strong> text ?</p>
<pre><code class="language-diff">Line foo&amp;Line3 1
Line 2
Line 3
Line 4
foo&amp;Line3 Line 5 
Line 6
Line 7 foo&amp;line3
</code></pre>
<p dir="auto">If so, I will be able to post a <strong>solution</strong>, next time, which does the job, with <strong>two</strong> consecutive <strong>regex</strong> search/replacements !</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/30000</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30000</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 04 Feb 2018 20:51:21 GMT</pubDate></item></channel></rss>