Skip to content

Commit a9258b0

Browse files
added another example for datamash
1 parent 7688960 commit a9258b0

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

atom.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
66
<link href="https://learnbyexample.github.io"/>
77
<generator uri="https://www.getzola.org/">Zola</generator>
8-
<updated>2024-04-11T00:00:00+00:00</updated>
8+
<updated>2024-04-22T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
1010
<entry xml:lang="en">
1111
<title>CLI computation with GNU datamash</title>
1212
<published>2024-04-09T00:00:00+00:00</published>
13-
<updated>2024-04-11T00:00:00+00:00</updated>
13+
<updated>2024-04-22T00:00:00+00:00</updated>
1414
<link rel="alternate" href="https://learnbyexample.github.io/cli-computation-gnu-datamash/" type="text/html"/>
1515
<id>https://learnbyexample.github.io/cli-computation-gnu-datamash/</id>
1616
<content type="html">&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;info.svg&quot; alt=&quot;info&quot; &#x2F;&gt; &lt;img src=&quot;&#x2F;images&#x2F;warning.svg&quot; alt=&quot;warning&quot; &#x2F;&gt; This is a work-in-progress post on the &lt;code&gt;GNU datamash&lt;&#x2F;code&gt; command.&lt;&#x2F;p&gt;
@@ -74,11 +74,21 @@
7474
&lt;&#x2F;span&gt;&lt;span&gt;rocket white
7575
&lt;&#x2F;span&gt;&lt;span&gt;
7676
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# by default a comma is used as the separator between collapsed items
77+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# use &amp;#39;unique&amp;#39; instead of &amp;#39;collapse&amp;#39; to avoid duplicates
7778
&lt;&#x2F;span&gt;&lt;span&gt;$ datamash &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;t&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39; &amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;g1 collapse &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;2 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;toys.txt
7879
&lt;&#x2F;span&gt;&lt;span&gt;car blue,red,yellow
7980
&lt;&#x2F;span&gt;&lt;span&gt;truck brown
8081
&lt;&#x2F;span&gt;&lt;span&gt;bus green,maroon
8182
&lt;&#x2F;span&gt;&lt;span&gt;rocket white
83+
&lt;&#x2F;span&gt;&lt;span&gt;
84+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# &amp;#39;count&amp;#39; gives the number of items for the collapsed row
85+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# &amp;#39;rand&amp;#39; selects a random item for such collapsed rows
86+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# &amp;#39;first&amp;#39; and &amp;#39;last&amp;#39; are other choices available
87+
&lt;&#x2F;span&gt;&lt;span&gt;$ datamash &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;t&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39; &amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;g1 count &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;2 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;rand &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;2 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;toys.txt
88+
&lt;&#x2F;span&gt;&lt;span&gt;car &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt; red
89+
&lt;&#x2F;span&gt;&lt;span&gt;truck &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt; brown
90+
&lt;&#x2F;span&gt;&lt;span&gt;bus &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt; green
91+
&lt;&#x2F;span&gt;&lt;span&gt;rocket &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt; white
8292
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
8393
&lt;p&gt;Here&#x27;s an example with header lines as well as having to sort the input (&lt;code&gt;-s&lt;&#x2F;code&gt;). The &lt;code&gt;-c&lt;&#x2F;code&gt; option helps to customize the separator for the grouped items. The &lt;code&gt;-H&lt;&#x2F;code&gt; option is equivalent to using both &lt;code&gt;--header-in&lt;&#x2F;code&gt; and &lt;code&gt;--header-out&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
8494
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span&gt;$ cat books.txt

cli-computation-gnu-datamash/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,21 @@
4343
</span><span>rocket white
4444
</span><span>
4545
</span><span style=color:#7f8989;># by default a comma is used as the separator between collapsed items
46+
</span><span style=color:#7f8989;># use 'unique' instead of 'collapse' to avoid duplicates
4647
</span><span>$ datamash </span><span style=color:#72ab00;>-</span><span>t</span><span style=color:#d07711;>' ' </span><span style=color:#72ab00;>-</span><span>g1 collapse </span><span style=color:#b3933a;>2 </span><span style=color:#72ab00;><</span><span>toys.txt
4748
</span><span>car blue,red,yellow
4849
</span><span>truck brown
4950
</span><span>bus green,maroon
5051
</span><span>rocket white
52+
</span><span>
53+
</span><span style=color:#7f8989;># 'count' gives the number of items for the collapsed row
54+
</span><span style=color:#7f8989;># 'rand' selects a random item for such collapsed rows
55+
</span><span style=color:#7f8989;># 'first' and 'last' are other choices available
56+
</span><span>$ datamash </span><span style=color:#72ab00;>-</span><span>t</span><span style=color:#d07711;>' ' </span><span style=color:#72ab00;>-</span><span>g1 count </span><span style=color:#b3933a;>2 </span><span style=color:#b39f04;>rand </span><span style=color:#b3933a;>2 </span><span style=color:#72ab00;><</span><span>toys.txt
57+
</span><span>car </span><span style=color:#b3933a;>3</span><span> red
58+
</span><span>truck </span><span style=color:#b3933a;>1</span><span> brown
59+
</span><span>bus </span><span style=color:#b3933a;>2</span><span> green
60+
</span><span>rocket </span><span style=color:#b3933a;>1</span><span> white
5161
</span></code></pre><p>Here's an example with header lines as well as having to sort the input (<code>-s</code>). The <code>-c</code> option helps to customize the separator for the grouped items. The <code>-H</code> option is equivalent to using both <code>--header-in</code> and <code>--header-out</code>.<pre class=language-python data-lang=python style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-python data-lang=python><span>$ cat books.txt
5262
</span><span>Author,Title
5363
</span><span>Will Wight,Cradle

sitemap.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</url>
3333
<url>
3434
<loc>https://learnbyexample.github.io/cli-computation-gnu-datamash/</loc>
35-
<lastmod>2024-04-11</lastmod>
35+
<lastmod>2024-04-22</lastmod>
3636
</url>
3737
<url>
3838
<loc>https://learnbyexample.github.io/cli-text-processing-awk-announcement/</loc>

0 commit comments

Comments
 (0)