<?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[Replace X number of lines after finding Y]]></title><description><![CDATA[<p dir="auto">I have a ton of text files that are cluttered with headers where there is a page break/FF symbol. The header always contains 6 lines starting at the FF symbol. I’m not sure how to search for a vague number of lines and/or characters after the unique FF starts off the header. The header also ends with “Y.T.D”. followed by an empty line, if that helps. In a perfect world, I’d like to remove the “(Continued)” aka 7th line only if the word “Continued” appears (in green below).</p>
<p dir="auto">Example (goal is to remove everything highlighted… for all of the page breaks/headers the file may contain):</p>
<p dir="auto"><img src="/assets/uploads/files/1590010991404-933b1861-6e86-4968-aa57-1be3bd98799d-image.png" alt="933b1861-6e86-4968-aa57-1be3bd98799d-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Thanks to all of the folks that created and maintain this software. I really appreciate ya’ll and your community!</p>
<p dir="auto">B</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/19442/replace-x-number-of-lines-after-finding-y</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 18:00:59 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/19442.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 May 2020 21:46:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Thu, 21 May 2020 18:44:43 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-krontz" aria-label="Profile: brian-krontz">@<bdi>brian-krontz</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: ekopalypse">@<bdi>ekopalypse</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</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/makwana-prahlad" aria-label="Profile: makwana-prahlad">@<bdi>makwana-prahlad</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">To <a class="plugin-mentions-user plugin-mentions-a" href="/user/makwana-prahlad" aria-label="Profile: makwana-prahlad">@<bdi>makwana-prahlad</bdi></a> :</p>
<p dir="auto">Why are you using such a <strong>complicated</strong> script, with some <strong>advanced</strong> options of <strong><code>sed </code></strong> ?</p>
<p dir="auto">To my mind, the <strong><code>one</code></strong>-line <strong>script</strong>, below, does the job <strong>nicely</strong>, too ;-))</p>
<p dir="auto"><strong><code>sed -n "/^\x0C/,+5d ; /(Continued)/d ; p" Input.txt &gt; Output.txt</code></strong></p>
<hr />
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">First, <strong><code>sed</code></strong> searches, in the <strong><code>Input.txt</code></strong> file,  for a <strong>range</strong> of lines :</p>
<ul>
<li>
<p dir="auto">The <strong>first</strong> line of this range <strong>must</strong> contain the <strong><code>FF</code></strong> char, at <strong>beginning</strong> of current line, so the <strong><code>/^\x0C/</code></strong> syntax</p>
</li>
<li>
<p dir="auto">Till the <strong>next</strong> <strong><code>5 lines</code></strong>, that is to say, till the <strong><code>6th</code></strong> <strong>empty</strong> line. Thus, the <strong><code>,+5</code></strong> syntax</p>
</li>
</ul>
</li>
<li>
<p dir="auto">Then, the <strong><code>d</code></strong> command <strong>deletes</strong> this range of <strong>entire</strong> lines</p>
</li>
<li>
<p dir="auto">Secondly, <strong><code>sed</code></strong> searches if the <strong>next</strong> <strong><code>7th</code></strong> line contains the <strong><code>(Continued)</code></strong> string, with that <strong>exact</strong> case, so the syntax <strong><code>/(Continued)/</code></strong> , and, in that case, the <strong><code>d</code></strong> command, again, <strong>deletes</strong> this <strong>current</strong> line</p>
</li>
<li>
<p dir="auto">Finally, if <strong>none</strong> of these criteria can be <strong>verified</strong>, the <strong><code>p</code></strong> command simply <strong>rewrites</strong> the <strong>current</strong> line in the <strong><code>Output.txt</code></strong> file</p>
</li>
</ul>
<hr />
<p dir="auto">Indeed, <strong>not</strong> the same <strong>philosophy</strong> at usual N++ <strong>regexes</strong>, but rather <strong>easy</strong> to understand, too !</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S.</strong> :</p>
<p dir="auto">My <strong><code>sed</code></strong> script is not <strong>totally</strong> exact ! Indeed, if a line, located <strong>outside</strong> the <strong><code>header</code></strong> zone, contains the string <strong><code>(Continued)</code></strong>, this line is <strong>wrongly</strong> deleted ! But, anyway, we’re on a <strong>Notepad++</strong> forum, after all ;-))</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54193</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54193</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 21 May 2020 18:44:43 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Thu, 21 May 2020 16:04:10 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-krontz" aria-label="Profile: brian-krontz">@<bdi>brian-krontz</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: ekopalypse">@<bdi>ekopalypse</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">For a better <strong>readability</strong>, if we use the <strong>free-spacing</strong> mode, <strong><code>(?x)</code></strong> modifier, my <strong>previous</strong> search regex can be rewritten as :</p>
<pre><code class="language-z">(?x)   (?s-i)   ^\x0C   .+?   Y\.T\.D\.   \h*\R   \h*\R   (?-s)   (?:   .+\(Continued\).*   \R   )?
</code></pre>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">First the part <strong><code>(?s-i)</code></strong> are <strong>in-line</strong> modifiers :</p>
<ul>
<li>
<p dir="auto"><strong><code>(?s)</code></strong> means that the <strong>dot</strong> regex symbol ( <strong><code>.</code></strong> ) represents any <strong>single</strong> character, even <strong>like-break</strong> chars like <strong><code>\r</code></strong> or <strong><code>\n</code></strong> ( <strong><code>single-line</code></strong> mode )</p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)</code></strong> carries out the search in a <strong>case-sensitive</strong> manner ( <strong><code>non-insensitive</code></strong>  mode )</p>
</li>
</ul>
</li>
<li>
<p dir="auto">Then, the part <strong><code>^\x0C</code></strong> searches for a <strong><code>FF</code></strong> <strong>control</strong> character, at <strong>beginning</strong> of lines ( <strong><code>^</code></strong> )</p>
</li>
<li>
<p dir="auto">Now, the <strong><code>.+?</code></strong> syntax looks for the <strong>shortest non-null</strong> range of <strong>any</strong> character, even <strong>line-breaks</strong>,  <em>TILL</em>…</p>
</li>
<li>
<p dir="auto">…the part <strong><code>Y\.T\.D\.\h*\R</code></strong>. That is to say …till the string <strong><code>Y.T.D.</code></strong>, with that <strong>exact</strong> case, followed by possible <strong>horizontal blank</strong> char(s) ( <strong><code>Tab</code></strong> / <strong><code>Space</code></strong> ) and its <strong>line-break</strong> , as <strong><code>\R</code></strong> match any kind of <strong>line-end</strong> char(s)</p>
</li>
<li>
<p dir="auto">And the <strong><code>\h*\R</code></strong> looks for a <strong>blank</strong> line ( the <strong><code>6th</code></strong> ), <strong>possibly</strong> preceded with <strong>horizontal blank</strong> character(s)</p>
</li>
<li>
<p dir="auto">Then, the <strong><code>(?-s)</code></strong> modifier means that, from now on, any regex <strong><code>.</code></strong> symbol matches a <strong>single standard</strong> character only ( <strong>not</strong> <strong><code>EOL</code></strong> ones )</p>
</li>
<li>
<p dir="auto">Now, the part <strong><code>.+\(Continued\).*\R</code></strong> searches, in <strong>current</strong> line, for <strong>any</strong> string, <strong><code>(Continued)</code></strong>, with this <strong>exact</strong> case, preceded with a <strong>non-null</strong> range of <strong>standard</strong> char(s) ( <strong><code>.+</code></strong> ) and followed with other range of <strong>standard</strong> char(s), possibly <strong>null</strong> ( <strong><code>.*</code></strong> ) and its <strong>line-break</strong> char(s) ( <strong><code>\R</code></strong> )</p>
</li>
<li>
<p dir="auto">As the <strong>above</strong> part is <strong>embedded</strong> in the structure <strong><code>(?:......)?</code></strong>, this means that <strong>all</strong> the <strong><code>7th</code></strong>-line contents are embedded in a <strong>non-capturing</strong> group, which may be <strong>optional</strong>, due to the <strong><code>?</code></strong> <strong>quantifier</strong>, at the <strong>end</strong> ( a shorthand of the <strong>formal</strong> syntax <strong><code>{0,1}</code></strong> )</p>
</li>
</ul>
<hr />
<p dir="auto"><strong>Remark</strong> : The <strong>dot</strong> <strong><code>.</code></strong> and <strong>parentheses</strong> <strong><code>()</code></strong> chars are <strong>regex</strong> symbols. So, in order to be interpreted as <strong>literal</strong> characters, they need to be <strong>escaped</strong> with the <strong><code>\</code></strong> symbol</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54164</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54164</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 21 May 2020 16:04:10 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Thu, 21 May 2020 11:49:31 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></p>
<p dir="auto">Why is it necessary to take this outside of Notepad++?<br />
This is a Notepad++ forum and if a solution can be found using Notepad++ then no discussion of outside tools is needed or wanted.<br />
Also, the question has been answered previously so there is no real need to seek further solutions.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54162</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54162</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 21 May 2020 11:49:31 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Thu, 21 May 2020 08:18:20 GMT]]></title><description><![CDATA[<p dir="auto">Hello,<a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-krontz" aria-label="Profile: Brian-Krontz">@<bdi>Brian-Krontz</bdi></a></p>
<p dir="auto">Please try this information,To Replace X number of lines after finding Y</p>
<p dir="auto">In the simplest calling of sed, it has one line of text in the pattern space, ie. 1 line of \n delimited text from the input. The single line in the pattern space has no \n… That’s why your regex is not finding anything.</p>
<p dir="auto">You can read multiple lines into the pattern-space and manipulate things surprisingly well, but with a more than normal effort… Sed has a set of commands which allow this type of thing… Here is a link to a Command Summary for sed. It is the best one I’ve found, and got me rolling.</p>
<p dir="auto">However forget the “one-liner” idea once you start using sed’s micro-commands. It is useful to lay it out like a structured program until you get the feel of it… It is surprisingly simple, and equally unusual. You could think of it as the “assembler language” of text editing.</p>
<p dir="auto">Summary: Use sed for simple things, and maybe a bit more, but in general, when it gets beyond working with a single line, most people prefer something else…<br />
I’ll let someone else suggest something else… I’m really not sure what the best choice would be (I’d use sed, but that’s because I don’t know perl well enough.)</p>
<pre><code>sed '/^a test$/{
       $!{ N        # append the next line when not on the last line
         s/^a test\nPlease do not$/not a test\nBe/
                    # now test for a successful substitution, otherwise
                    #+  unpaired "a test" lines would be mis-handled
         t sub-yes  # branch_on_substitute (goto label :sub-yes)
         :sub-not   # a label (not essential; here to self document)
                    # if no substituion, print only the first line
         P          # pattern_first_line_print
         D          # pattern_ltrunc(line+nl)_top/cycle
         :sub-yes   # a label (the goto target of the 't' branch)
                    # fall through to final auto-pattern_print (2 lines)
       }    
     }' alpha.txt
</code></pre>
<p dir="auto">I hope this information will be usefull for you.<br />
Thank you.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54160</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54160</guid><dc:creator><![CDATA[Makwana Prahlad]]></dc:creator><pubDate>Thu, 21 May 2020 08:18:20 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Wed, 20 May 2020 22:51:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said in <a href="/post/54155">Replace X number of lines after finding Y</a>:</p>
<blockquote>
<p dir="auto">where do you see an issue that my regex</p>
</blockquote>
<p dir="auto">My concern was for the OP. The example provided would seem to be accountancy stuff. VERY important data and I was just letting him know that IF HE WAS concerned this was a way to verify the correct lines were removed. As you will see, he had another method to prove that anyways (Beyond Compare).</p>
<p dir="auto">Cheers<br />
Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54157</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54157</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Wed, 20 May 2020 22:51:23 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Wed, 20 May 2020 22:47:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a> said in <a href="/post/54152">Replace X number of lines after finding Y</a>:</p>
<blockquote>
<p dir="auto">Just in case you were worried about removing more lines than you wanted I’d suggest using <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>  regex</p>
</blockquote>
<p dir="auto">Just curious, where do you see an issue that my regex<br />
might remove more lines then expected?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54155</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54155</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Wed, 20 May 2020 22:47:38 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Wed, 20 May 2020 22:24:57 GMT]]></title><description><![CDATA[<p dir="auto">You guys are amazing. I checked the results in Beyond Compare and everything looks perfect. Guy, it worked, so explain away if you’d like. Eko and Terry, I think he’s got me fixed up, but appreciate the extra set of eyes.  Thanks to all!!</p>
<p dir="auto">B</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54153</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54153</guid><dc:creator><![CDATA[Brian Krontz]]></dc:creator><pubDate>Wed, 20 May 2020 22:24:57 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Wed, 20 May 2020 22:20:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-krontz" aria-label="Profile: Brian-Krontz">@<bdi>Brian-Krontz</bdi></a><br />
Just in case you were worried about removing more lines than you wanted I’d suggest using <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>  regex, but with the “Mark” function and tick the bookmark line. Then you could “mark all” and go through the document/file to verify it was ONLY the lines you wanted were marked. Then once confirmed use the “Remove bookmarked Lines” from under Search (main menu), Bookmark.</p>
<p dir="auto">I too was working on an almost exact copy of <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>  regex but he was faster to the keyboard.</p>
<p dir="auto">Good luck<br />
Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54152</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54152</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Wed, 20 May 2020 22:20:18 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Wed, 20 May 2020 22:14:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-krontz" aria-label="Profile: Brian-Krontz">@<bdi>Brian-Krontz</bdi></a></p>
<p dir="auto">depending on your real data this might work.<br />
Find what:<code>\x0C(.*\R){6}.*Y\.T\.D\r\n\r\n.*\(Continued\)|\x0C(.*\R){6}.*Y\.T\.D</code><br />
leave replace with empty and check <em>regular expression</em> in search mode</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54150</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54150</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Wed, 20 May 2020 22:14:00 GMT</pubDate></item><item><title><![CDATA[Reply to Replace X number of lines after finding Y on Thu, 21 May 2020 11:58:20 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/brian-krontz" aria-label="Profile: brian-krontz">@<bdi>brian-krontz</bdi></a>, and <strong>All</strong>,</p>
<p dir="auto"><strong>Easy</strong> with <strong>regular</strong> expressions ! The following <strong>regex</strong> S/R should work :</p>
<ul>
<li>
<p dir="auto">Open the <strong>Replace</strong> dialog ( <strong><code>Ctrl + H</code></strong> )</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s-i)^\x0C.+?Y\.T\.D\.\h*\R\h*\R(?-s)(?:.+\(Continued\).*\R)?</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
</li>
<li>
<p dir="auto">Tick the <strong><code>Wrap around</code></strong> option</p>
</li>
<li>
<p dir="auto">Select the <strong><code>Regular expression</code></strong> search mode</p>
</li>
<li>
<p dir="auto">CLick <strong>once</strong> on the <strong><code>Replace All</code></strong> button or <strong>several</strong> times on the <strong><code>Replace</code></strong> button</p>
</li>
</ul>
<p dir="auto">Voila !</p>
<p dir="auto">If it <strong>solves</strong> your problem, I’ll explain the <strong>regex</strong> syntax <strong>next</strong> time !</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/54149</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/54149</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 21 May 2020 11:58:20 GMT</pubDate></item></channel></rss>