<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>textediting on Alán's blog</title><link>https://quasimorphic.com/tags/textediting/</link><description>Recent content in textediting on Alán's blog</description><generator>Hugo</generator><language>en-uk</language><lastBuildDate>Thu, 14 Aug 2025 15:42:00 -0400</lastBuildDate><atom:link href="https://quasimorphic.com/tags/textediting/index.xml" rel="self" type="application/rss+xml"/><item><title>Update figure numbering</title><link>https://quasimorphic.com/archive/awk-update-figure-numbering/</link><pubDate>Thu, 14 Aug 2025 15:42:00 -0400</pubDate><guid>https://quasimorphic.com/archive/awk-update-figure-numbering/</guid><description>&lt;p>I was editing some markdown and had to insert a new figure in the middle. The problem is that this document already has an explicit figure numbering (e.g., &amp;ldquo;Figure 5&amp;rdquo;), so changing tens of figures felt dull. I like to run small (GNU) &lt;code>awk&lt;/code> scripts for this type of tasks.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-awk" data-lang="awk">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># update_figures.awk&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (&lt;span style="color:#66d9ef">match&lt;/span>(&lt;span style="color:#f92672">$&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;Figure ([0-9]+)&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">num&lt;/span>)){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (&lt;span style="color:#a6e22e">num&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>] &lt;span style="color:#f92672">&amp;gt;&lt;/span> &lt;span style="color:#a6e22e">after&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">gsub&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;Figure ([0-9]+)&amp;#34;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;Figure &amp;#34;&lt;/span> &lt;span style="color:#a6e22e">num&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>] &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#a6e22e">increase_by&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> };
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">print&lt;/span> &lt;span style="color:#f92672">$&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This changes Figure &lt;code>X&lt;/code> into Figure &lt;code>X&lt;/code> + &lt;code>increase_by&lt;/code> starting after the variable &amp;ldquo;after&amp;rdquo;. And we can run it as follows:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>awk -v after&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">4&lt;/span> -v increase_by&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span> -f update_figures.awk input_file.md
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>To edit the file in-place add the &lt;code>-i&lt;/code> flag.&lt;/p></description></item>/<item><title>Recursive search and replace</title><link>https://quasimorphic.com/archive/recursive-search-replace/</link><pubDate>Tue, 12 Aug 2025 13:07:00 -0400</pubDate><guid>https://quasimorphic.com/archive/recursive-search-replace/</guid><description>&lt;p>I needed to rename all occurrences of a pattern with another, where I knew there was no ambiguous situations. This uses &lt;code>ripgrep&lt;/code>, &lt;code>xargs&lt;/code> and &lt;code>GNU sed&lt;/code>. &lt;a href="https://github.com/BurntSushi/ripgrep/blob/master/FAQ.md#search-and-replace">source&lt;/a>.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>rg old_pattern --files-with-matches | xargs sed -i &lt;span style="color:#e6db74">&amp;#39;s/old_pattern/new_pattern/g&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item>/</channel></rss>