<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knowledge Base (Posts about compare)</title><link>https://bgstack15.ddns.net/blog/</link><description></description><atom:link href="https://bgstack15.ddns.net/blog/categories/compare.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2022 &lt;a href="mailto:bgstack15@gmail.com"&gt;bgstack15&lt;/a&gt; 
&lt;a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
style="border-width:0; margin-bottom:12px;"
src="https://bgstack15.ddns.net/.images/l_by-sa_4.0_88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Mon, 14 Mar 2022 18:59:20 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Awk: compare version strings</title><link>https://bgstack15.ddns.net/blog/posts/2020/10/28/awk-compare-version-strings/</link><dc:creator>bgstack15</dc:creator><description>&lt;p&gt;When I was working on my dpkg for &lt;a href="https://notepad-plus-plus.org"&gt;notepad++&lt;/a&gt;,
I discovered that the naming convention changed for the release assets. So
starting with version 7.9, the filenames include ".portable" instead of
".bin." I don't care about the change, but I need my automatic downloader to
handle it. So, I had to add some logic for checking if the requested version
number is greater than or equal to 7.9. But there is another layer of sub-
version to deal with, because I know the previous release was 7.8.9. So I
whipped up some awk to help me.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nv"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;7.8.9&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;awk&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;v&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;maxsections=3&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;F&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NF &amp;lt; maxsections {printf("%s",$0);for(i=NF;i&amp;lt;maxsections;i++)printf("%s",".0");printf("&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;")} NF &amp;gt;= maxsections {print}&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;awk&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;v&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;maxdigits=2&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;F&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;{print $1*10^(maxdigits*2)+$2*10^(maxdigits)+$3}&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The output will look like:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="mf"&gt;70809&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Which can then just be compared as a number with 70900 and then I can use the
new naming convention. The tunables in this snippet include the awk variables:
maxsections, and maxdigits. If the input version strings were to contain large
numbers, such as "7.20.5" or "6028.423.2143" then you can increase the
maxdigits. I realize that the second awk statement only handles a hard-coded
amount of 3 sections. I need to figure out how to improve it so it can
dynamically handle the number of sections defined in "maxsections" and handle
the output when the maxsections is lower than the amount of fields being
printed.&lt;/p&gt;</description><category>awk</category><category>compare</category><category>oneliner</category><category>version</category><guid>https://bgstack15.ddns.net/blog/posts/2020/10/28/awk-compare-version-strings/</guid><pubDate>Wed, 28 Oct 2020 12:43:44 GMT</pubDate></item><item><title>Compare two files in hexadecimal view</title><link>https://bgstack15.ddns.net/blog/posts/2019/09/13/compare-two-files-in-hexadecimal-view/</link><dc:creator>bgstack15</dc:creator><description>&lt;p&gt;Just a quick and dirty list for myself. When I was looking for hexeditors with
a file-compare view, these came up. All three of these options seem useful in
slightly different ways. &lt;a href="https://www.cjmweb.net/vbindiff/"&gt;vbindiff&lt;/a&gt;
&lt;a href="http://manpages.ubuntu.com/manpages/precise/man1/dhex.1.html"&gt;dhex&lt;/a&gt;
&lt;a href="http://vimdoc.sourceforge.net/htmldoc/diff.html"&gt;vimdiff&lt;/a&gt; and :%!xxd Vimdiff
just calls vim with a bunch of preset options.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;vimdiff file1 file2
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once inside, you have to convert each file with &lt;strong&gt;:%!xxd&lt;/strong&gt; and then after
making any changes, convert back with &lt;strong&gt;:%!xxd -r&lt;/strong&gt; before saving. Slightly
clunky, and I'm sure there's a way to automate all that. But I was only making
select changes. And a few keystrokes isn't so bad.&lt;/p&gt;</description><category>compare</category><category>hexedit</category><category>vim</category><guid>https://bgstack15.ddns.net/blog/posts/2019/09/13/compare-two-files-in-hexadecimal-view/</guid><pubDate>Fri, 13 Sep 2019 12:40:51 GMT</pubDate></item></channel></rss>