|
5 | 5 | <link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
|
6 | 6 | <link href="https://learnbyexample.github.io"/>
|
7 | 7 | <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> |
9 | 9 | <id>https://learnbyexample.github.io/atom.xml</id>
|
10 | 10 | <entry xml:lang="en">
|
11 | 11 | <title>CLI computation with GNU datamash</title>
|
12 | 12 | <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> |
14 | 14 | <link rel="alternate" href="https://learnbyexample.github.io/cli-computation-gnu-datamash/" type="text/html"/>
|
15 | 15 | <id>https://learnbyexample.github.io/cli-computation-gnu-datamash/</id>
|
16 | 16 | <content type="html"><p><img src="/images/info.svg" alt="info" /> <img src="/images/warning.svg" alt="warning" /> This is a work-in-progress post on the <code>GNU datamash</code> command.</p>
|
|
74 | 74 | </span><span>rocket white
|
75 | 75 | </span><span>
|
76 | 76 | </span><span style="color:#7f8989;"># by default a comma is used as the separator between collapsed items
|
| 77 | +</span><span style="color:#7f8989;"># use &#39;unique&#39; instead of &#39;collapse&#39; to avoid duplicates |
77 | 78 | </span><span>$ datamash </span><span style="color:#72ab00;">-</span><span>t</span><span style="color:#d07711;">&#39; &#39; </span><span style="color:#72ab00;">-</span><span>g1 collapse </span><span style="color:#b3933a;">2 </span><span style="color:#72ab00;">&lt;</span><span>toys.txt
|
78 | 79 | </span><span>car blue,red,yellow
|
79 | 80 | </span><span>truck brown
|
80 | 81 | </span><span>bus green,maroon
|
81 | 82 | </span><span>rocket white
|
| 83 | +</span><span> |
| 84 | +</span><span style="color:#7f8989;"># &#39;count&#39; gives the number of items for the collapsed row |
| 85 | +</span><span style="color:#7f8989;"># &#39;rand&#39; selects a random item for such collapsed rows |
| 86 | +</span><span style="color:#7f8989;"># &#39;first&#39; and &#39;last&#39; are other choices available |
| 87 | +</span><span>$ datamash </span><span style="color:#72ab00;">-</span><span>t</span><span style="color:#d07711;">&#39; &#39; </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;">&lt;</span><span>toys.txt |
| 88 | +</span><span>car </span><span style="color:#b3933a;">3</span><span> red |
| 89 | +</span><span>truck </span><span style="color:#b3933a;">1</span><span> brown |
| 90 | +</span><span>bus </span><span style="color:#b3933a;">2</span><span> green |
| 91 | +</span><span>rocket </span><span style="color:#b3933a;">1</span><span> white |
82 | 92 | </span></code></pre>
|
83 | 93 | <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>.</p>
|
84 | 94 | <pre data-lang="python" style="background-color:#f5f5f5;color:#1f1f1f;" class="language-python "><code class="language-python" data-lang="python"><span>$ cat books.txt
|
|
0 commit comments