mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-21 10:29:02 +00:00
537 lines
No EOL
26 KiB
HTML
537 lines
No EOL
26 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>Miller by example — Miller 6.0.0-alpha documentation</title>
|
||
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||
|
||
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
||
<script src="_static/jquery.js"></script>
|
||
<script src="_static/underscore.js"></script>
|
||
<script src="_static/doctools.js"></script>
|
||
<script src="_static/language_data.js"></script>
|
||
|
||
<link rel="index" title="Index" href="genindex.html" />
|
||
<link rel="search" title="Search" href="search.html" />
|
||
</head><body>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="nav-item nav-item-0"><a href="index.html">Miller 6.0.0-alpha documentation</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Miller by example</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<div class="section" id="miller-by-example">
|
||
<h1>Miller by example<a class="headerlink" href="#miller-by-example" title="Permalink to this headline">¶</a></h1>
|
||
<div class="section" id="obtaining-miller">
|
||
<h2>Obtaining Miller<a class="headerlink" href="#obtaining-miller" title="Permalink to this headline">¶</a></h2>
|
||
<p>You can install Miller for various platforms as follows:</p>
|
||
<ul class="simple">
|
||
<li><p>Linux: <code class="docutils literal notranslate"><span class="pre">yum</span> <span class="pre">install</span> <span class="pre">miller</span></code> or <code class="docutils literal notranslate"><span class="pre">apt-get</span> <span class="pre">install</span> <span class="pre">miller</span></code> depending on your flavor of Linux</p></li>
|
||
<li><p>MacOS: <code class="docutils literal notranslate"><span class="pre">brew</span> <span class="pre">install</span> <span class="pre">miller</span></code> or <code class="docutils literal notranslate"><span class="pre">port</span> <span class="pre">install</span> <span class="pre">miller</span></code> depending on your preference of <a class="reference external" href="https://brew.sh">Homebrew</a> or <a class="reference external" href="https://macports.org">MacPorts</a> .</p></li>
|
||
<li><p>Windows: <code class="docutils literal notranslate"><span class="pre">choco</span> <span class="pre">install</span> <span class="pre">miller</span></code> using <a class="reference external" href="https://chocolatey.org">Chocolatey</a> .</p></li>
|
||
<li><p>See also <a class="reference internal" href="build.html"><span class="doc">Building from source</span></a> if you prefer – in particular, if your platform’s package manager doesn’t have the latest release.</p></li>
|
||
</ul>
|
||
<p>Regardless, as a first check, at your system’s command prompt, you should be able to run <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">--version</span></code> and see something like the following:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --version
|
||
</span> Miller v6.0.0-dev
|
||
</pre></div>
|
||
</div>
|
||
<p>As a second check, given (<a class="reference external" href="./example.csv">example.csv</a>) you should be able to do</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --csv cat example.csv
|
||
</span> color,shape,flag,index,quantity,rate
|
||
yellow,triangle,true,11,43.6498,9.8870
|
||
red,square,true,15,79.2778,0.0130
|
||
red,circle,true,16,13.8103,2.9010
|
||
red,square,false,48,77.5542,7.4670
|
||
purple,triangle,false,51,81.2290,8.5910
|
||
red,square,false,64,77.1991,9.5310
|
||
purple,triangle,false,65,80.1405,5.8240
|
||
yellow,circle,true,73,63.9785,4.2370
|
||
yellow,circle,true,87,63.5058,8.3350
|
||
purple,square,false,91,72.3735,8.2430
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint cat example.csv
|
||
</span> color shape flag index quantity rate
|
||
yellow triangle true 11 43.6498 9.8870
|
||
red square true 15 79.2778 0.0130
|
||
red circle true 16 13.8103 2.9010
|
||
red square false 48 77.5542 7.4670
|
||
purple triangle false 51 81.2290 8.5910
|
||
red square false 64 77.1991 9.5310
|
||
purple triangle false 65 80.1405 5.8240
|
||
yellow circle true 73 63.9785 4.2370
|
||
yellow circle true 87 63.5058 8.3350
|
||
purple square false 91 72.3735 8.2430
|
||
</pre></div>
|
||
</div>
|
||
<p>If you run into issues on these checks, please check out the resources on the <a class="reference internal" href="community.html"><span class="doc">Community</span></a> page for help.</p>
|
||
</div>
|
||
<div class="section" id="miller-verbs">
|
||
<h2>Miller verbs<a class="headerlink" href="#miller-verbs" title="Permalink to this headline">¶</a></h2>
|
||
<p>Let’s take a quick look at some of the most useful Miller verbs – file-format-aware, name-index-empowered equivalents of standard system comments.</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">cat</span></code> is like cat – it passes the data through unmodified:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --csv cat example.csv
|
||
</span> color,shape,flag,index,quantity,rate
|
||
yellow,triangle,true,11,43.6498,9.8870
|
||
red,square,true,15,79.2778,0.0130
|
||
red,circle,true,16,13.8103,2.9010
|
||
red,square,false,48,77.5542,7.4670
|
||
purple,triangle,false,51,81.2290,8.5910
|
||
red,square,false,64,77.1991,9.5310
|
||
purple,triangle,false,65,80.1405,5.8240
|
||
yellow,circle,true,73,63.9785,4.2370
|
||
yellow,circle,true,87,63.5058,8.3350
|
||
purple,square,false,91,72.3735,8.2430
|
||
</pre></div>
|
||
</div>
|
||
<p>but it can also do format conversion (here, you can pretty-print in tabular format):</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint cat example.csv
|
||
</span> color shape flag index quantity rate
|
||
yellow triangle true 11 43.6498 9.8870
|
||
red square true 15 79.2778 0.0130
|
||
red circle true 16 13.8103 2.9010
|
||
red square false 48 77.5542 7.4670
|
||
purple triangle false 51 81.2290 8.5910
|
||
red square false 64 77.1991 9.5310
|
||
purple triangle false 65 80.1405 5.8240
|
||
yellow circle true 73 63.9785 4.2370
|
||
yellow circle true 87 63.5058 8.3350
|
||
purple square false 91 72.3735 8.2430
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --ojson cat example.csv
|
||
</span> {
|
||
"color": "yellow",
|
||
"shape": "triangle",
|
||
"flag": true,
|
||
"index": 11,
|
||
"quantity": 43.6498,
|
||
"rate": 9.8870
|
||
}
|
||
{
|
||
"color": "red",
|
||
"shape": "square",
|
||
"flag": true,
|
||
"index": 15,
|
||
"quantity": 79.2778,
|
||
"rate": 0.0130
|
||
}
|
||
{
|
||
"color": "red",
|
||
"shape": "circle",
|
||
"flag": true,
|
||
"index": 16,
|
||
"quantity": 13.8103,
|
||
"rate": 2.9010
|
||
}
|
||
{
|
||
"color": "red",
|
||
"shape": "square",
|
||
"flag": false,
|
||
"index": 48,
|
||
"quantity": 77.5542,
|
||
"rate": 7.4670
|
||
}
|
||
{
|
||
"color": "purple",
|
||
"shape": "triangle",
|
||
"flag": false,
|
||
"index": 51,
|
||
"quantity": 81.2290,
|
||
"rate": 8.5910
|
||
}
|
||
{
|
||
"color": "red",
|
||
"shape": "square",
|
||
"flag": false,
|
||
"index": 64,
|
||
"quantity": 77.1991,
|
||
"rate": 9.5310
|
||
}
|
||
{
|
||
"color": "purple",
|
||
"shape": "triangle",
|
||
"flag": false,
|
||
"index": 65,
|
||
"quantity": 80.1405,
|
||
"rate": 5.8240
|
||
}
|
||
{
|
||
"color": "yellow",
|
||
"shape": "circle",
|
||
"flag": true,
|
||
"index": 73,
|
||
"quantity": 63.9785,
|
||
"rate": 4.2370
|
||
}
|
||
{
|
||
"color": "yellow",
|
||
"shape": "circle",
|
||
"flag": true,
|
||
"index": 87,
|
||
"quantity": 63.5058,
|
||
"rate": 8.3350
|
||
}
|
||
{
|
||
"color": "purple",
|
||
"shape": "square",
|
||
"flag": false,
|
||
"index": 91,
|
||
"quantity": 72.3735,
|
||
"rate": 8.2430
|
||
}
|
||
</pre></div>
|
||
</div>
|
||
<p><code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">head</span></code> and <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">tail</span></code> count records rather than lines. Whether you’re getting the first few records or the last few, the CSV header is included either way:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --csv head -n 4 example.csv
|
||
</span> color,shape,flag,index,quantity,rate
|
||
yellow,triangle,true,11,43.6498,9.8870
|
||
red,square,true,15,79.2778,0.0130
|
||
red,circle,true,16,13.8103,2.9010
|
||
red,square,false,48,77.5542,7.4670
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --csv tail -n 4 example.csv
|
||
</span> color,shape,flag,index,quantity,rate
|
||
purple,triangle,false,65,80.1405,5.8240
|
||
yellow,circle,true,73,63.9785,4.2370
|
||
yellow,circle,true,87,63.5058,8.3350
|
||
purple,square,false,91,72.3735,8.2430
|
||
</pre></div>
|
||
</div>
|
||
<p>You can sort on a single field:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint sort -f shape example.csv
|
||
</span> color shape flag index quantity rate
|
||
red circle true 16 13.8103 2.9010
|
||
yellow circle true 73 63.9785 4.2370
|
||
yellow circle true 87 63.5058 8.3350
|
||
red square true 15 79.2778 0.0130
|
||
red square false 48 77.5542 7.4670
|
||
red square false 64 77.1991 9.5310
|
||
purple square false 91 72.3735 8.2430
|
||
yellow triangle true 11 43.6498 9.8870
|
||
purple triangle false 51 81.2290 8.5910
|
||
purple triangle false 65 80.1405 5.8240
|
||
</pre></div>
|
||
</div>
|
||
<p>You can sort primarily alphabetically on one field, then secondarily numerically descending on another field:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint sort -f shape -nr index example.csv
|
||
</span> color shape flag index quantity rate
|
||
yellow circle true 87 63.5058 8.3350
|
||
yellow circle true 73 63.9785 4.2370
|
||
red circle true 16 13.8103 2.9010
|
||
purple square false 91 72.3735 8.2430
|
||
red square false 64 77.1991 9.5310
|
||
red square false 48 77.5542 7.4670
|
||
red square true 15 79.2778 0.0130
|
||
purple triangle false 65 80.1405 5.8240
|
||
purple triangle false 51 81.2290 8.5910
|
||
yellow triangle true 11 43.6498 9.8870
|
||
</pre></div>
|
||
</div>
|
||
<p>If there are fields you don’t want to see in your data, you can use <code class="docutils literal notranslate"><span class="pre">cut</span></code> to keep only the ones you want, in the same order they appeared in the input data:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint cut -f flag,shape example.csv
|
||
</span> shape flag
|
||
triangle true
|
||
square true
|
||
circle true
|
||
square false
|
||
triangle false
|
||
square false
|
||
triangle false
|
||
circle true
|
||
circle true
|
||
square false
|
||
</pre></div>
|
||
</div>
|
||
<p>You can also use <code class="docutils literal notranslate"><span class="pre">cut</span> <span class="pre">-o</span></code> to keep specified fields, but in your preferred order:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint cut -o -f flag,shape example.csv
|
||
</span> flag shape
|
||
true triangle
|
||
true square
|
||
true circle
|
||
false square
|
||
false triangle
|
||
false square
|
||
false triangle
|
||
true circle
|
||
true circle
|
||
false square
|
||
</pre></div>
|
||
</div>
|
||
<p>You can use <code class="docutils literal notranslate"><span class="pre">cut</span> <span class="pre">-x</span></code> to omit fields you don’t care about:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint cut -x -f flag,shape example.csv
|
||
</span> color index quantity rate
|
||
yellow 11 43.6498 9.8870
|
||
red 15 79.2778 0.0130
|
||
red 16 13.8103 2.9010
|
||
red 48 77.5542 7.4670
|
||
purple 51 81.2290 8.5910
|
||
red 64 77.1991 9.5310
|
||
purple 65 80.1405 5.8240
|
||
yellow 73 63.9785 4.2370
|
||
yellow 87 63.5058 8.3350
|
||
purple 91 72.3735 8.2430
|
||
</pre></div>
|
||
</div>
|
||
<p>You can use <code class="docutils literal notranslate"><span class="pre">filter</span></code> to keep only records you care about:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint filter '$color == "red"' example.csv
|
||
</span> color shape flag index quantity rate
|
||
red square true 15 79.2778 0.0130
|
||
red circle true 16 13.8103 2.9010
|
||
red square false 48 77.5542 7.4670
|
||
red square false 64 77.1991 9.5310
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint filter '$color == "red" && $flag == 1' example.csv
|
||
</span></pre></div>
|
||
</div>
|
||
<p>You can use <code class="docutils literal notranslate"><span class="pre">put</span></code> to create new fields which are computed from other fields:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint put '$ratio = $quantity / $rate; $color_shape = $color . "_" . $shape' example.csv
|
||
</span> color shape flag index quantity rate ratio color_shape
|
||
yellow triangle true 11 43.6498 9.8870 4.414868008496004 yellow_triangle
|
||
red square true 15 79.2778 0.0130 6098.292307692308 red_square
|
||
red circle true 16 13.8103 2.9010 4.760530851430541 red_circle
|
||
red square false 48 77.5542 7.4670 10.386259541984733 red_square
|
||
purple triangle false 51 81.2290 8.5910 9.455127458968688 purple_triangle
|
||
red square false 64 77.1991 9.5310 8.099790158430384 red_square
|
||
purple triangle false 65 80.1405 5.8240 13.760388049450551 purple_triangle
|
||
yellow circle true 73 63.9785 4.2370 15.09995279679018 yellow_circle
|
||
yellow circle true 87 63.5058 8.3350 7.619172165566886 yellow_circle
|
||
purple square false 91 72.3735 8.2430 8.779995147397793 purple_square
|
||
</pre></div>
|
||
</div>
|
||
<p>Even though Miller’s main selling point is name-indexing, sometimes you really want to refer to a field name by its positional index. Use <code class="docutils literal notranslate"><span class="pre">$[[3]]</span></code> to access the name of field 3 or <code class="docutils literal notranslate"><span class="pre">$[[[3]]]</span></code> to access the value of field 3:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint put '$[[3]] = "NEW"' example.csv
|
||
</span> color shape NEW index quantity rate
|
||
yellow triangle true 11 43.6498 9.8870
|
||
red square true 15 79.2778 0.0130
|
||
red circle true 16 13.8103 2.9010
|
||
red square false 48 77.5542 7.4670
|
||
purple triangle false 51 81.2290 8.5910
|
||
red square false 64 77.1991 9.5310
|
||
purple triangle false 65 80.1405 5.8240
|
||
yellow circle true 73 63.9785 4.2370
|
||
yellow circle true 87 63.5058 8.3350
|
||
purple square false 91 72.3735 8.2430
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --icsv --opprint put '$[[[3]]] = "NEW"' example.csv
|
||
</span> color shape flag index quantity rate
|
||
yellow triangle NEW 11 43.6498 9.8870
|
||
red square NEW 15 79.2778 0.0130
|
||
red circle NEW 16 13.8103 2.9010
|
||
red square NEW 48 77.5542 7.4670
|
||
purple triangle NEW 51 81.2290 8.5910
|
||
red square NEW 64 77.1991 9.5310
|
||
purple triangle NEW 65 80.1405 5.8240
|
||
yellow circle NEW 73 63.9785 4.2370
|
||
yellow circle NEW 87 63.5058 8.3350
|
||
purple square NEW 91 72.3735 8.2430
|
||
</pre></div>
|
||
</div>
|
||
<p>You can find the full list of verbs at the <a class="reference internal" href="reference-verbs.html"><span class="doc">Verbs reference</span></a> page.</p>
|
||
</div>
|
||
<div class="section" id="tbf">
|
||
<h2>TBF<a class="headerlink" href="#tbf" title="Permalink to this headline">¶</a></h2>
|
||
<p>some simple then-chains – keep it simple</p>
|
||
<p>printing to files – keep it simple here too</p>
|
||
</div>
|
||
<div class="section" id="choices-for-printing-to-files">
|
||
<h2>Choices for printing to files<a class="headerlink" href="#choices-for-printing-to-files" title="Permalink to this headline">¶</a></h2>
|
||
<p>Often we want to print output to the screen. Miller does this by default, as we’ve seen in the previous examples.</p>
|
||
<p>Sometimes we want to print output to another file: just use <strong>> outputfilenamegoeshere</strong> at the end of your command:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> % mlr --icsv --opprint cat example.csv > newfile.csv
|
||
</span> # Output goes to the new file;
|
||
# nothing is printed to the screen.
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> % cat newfile.csv
|
||
</span> color shape flag index quantity rate
|
||
yellow triangle 1 11 43.6498 9.8870
|
||
red square 1 15 79.2778 0.0130
|
||
red circle 1 16 13.8103 2.9010
|
||
red square 0 48 77.5542 7.4670
|
||
purple triangle 0 51 81.2290 8.5910
|
||
red square 0 64 77.1991 9.5310
|
||
purple triangle 0 65 80.1405 5.8240
|
||
yellow circle 1 73 63.9785 4.2370
|
||
yellow circle 1 87 63.5058 8.3350
|
||
purple square 0 91 72.3735 8.2430
|
||
</pre></div>
|
||
</div>
|
||
<p>Other times we just want our files to be <strong>changed in-place</strong>: just use <strong>mlr -I</strong>:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> % cp example.csv newfile.txt
|
||
</span></pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> % cat newfile.txt
|
||
</span> color,shape,flag,index,quantity,rate
|
||
yellow,triangle,1,11,43.6498,9.8870
|
||
red,square,1,15,79.2778,0.0130
|
||
red,circle,1,16,13.8103,2.9010
|
||
red,square,0,48,77.5542,7.4670
|
||
purple,triangle,0,51,81.2290,8.5910
|
||
red,square,0,64,77.1991,9.5310
|
||
purple,triangle,0,65,80.1405,5.8240
|
||
yellow,circle,1,73,63.9785,4.2370
|
||
yellow,circle,1,87,63.5058,8.3350
|
||
purple,square,0,91,72.3735,8.2430
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> % mlr -I --icsv --opprint cat newfile.txt
|
||
</span></pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> % cat newfile.txt
|
||
</span> color shape flag index quantity rate
|
||
yellow triangle 1 11 43.6498 9.8870
|
||
red square 1 15 79.2778 0.0130
|
||
red circle 1 16 13.8103 2.9010
|
||
red square 0 48 77.5542 7.4670
|
||
purple triangle 0 51 81.2290 8.5910
|
||
red square 0 64 77.1991 9.5310
|
||
purple triangle 0 65 80.1405 5.8240
|
||
yellow circle 1 73 63.9785 4.2370
|
||
yellow circle 1 87 63.5058 8.3350
|
||
purple square 0 91 72.3735 8.2430
|
||
</pre></div>
|
||
</div>
|
||
<p>Also using <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">-I</span></code> you can bulk-operate on lots of files: e.g.:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> mlr -I --csv cut -x -f unwanted_column_name *.csv
|
||
</span></pre></div>
|
||
</div>
|
||
<p>If you like, you can first copy off your original data somewhere else, before doing in-place operations.</p>
|
||
<p>Lastly, using <code class="docutils literal notranslate"><span class="pre">tee</span></code> within <code class="docutils literal notranslate"><span class="pre">put</span></code>, you can split your input data into separate files per one or more field names:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ mlr --csv --from example.csv put -q 'tee > $shape.".csv", $*'
|
||
</span></pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat circle.csv
|
||
</span> color,shape,flag,index,quantity,rate
|
||
red,circle,true,16,13.8103,2.9010
|
||
yellow,circle,true,73,63.9785,4.2370
|
||
yellow,circle,true,87,63.5058,8.3350
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat square.csv
|
||
</span> color,shape,flag,index,quantity,rate
|
||
red,square,true,15,79.2778,0.0130
|
||
red,square,false,48,77.5542,7.4670
|
||
red,square,false,64,77.1991,9.5310
|
||
purple,square,false,91,72.3735,8.2430
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> $ cat triangle.csv
|
||
</span> color,shape,flag,index,quantity,rate
|
||
yellow,triangle,true,11,43.6498,9.8870
|
||
purple,triangle,false,51,81.2290,8.5910
|
||
purple,triangle,false,65,80.1405,5.8240
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="id1">
|
||
<h2>TBF<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
|
||
<p>What’s a CSV file, really? It’s an array of rows, or <em>records</em>, each being a list of key-value pairs, or <em>fields</em>: for CSV it so happens that all the keys are shared in the header line and the values vary data line by data line.</p>
|
||
<p>For example, if you have:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>shape,flag,index
|
||
circle,1,24
|
||
square,0,36
|
||
</pre></div>
|
||
</div>
|
||
<p>then that’s a way of saying:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>shape=circle,flag=1,index=24
|
||
shape=square,flag=0,index=36
|
||
</pre></div>
|
||
</div>
|
||
<p>Data written this way are called <strong>DKVP</strong>, for <em>delimited key-value pairs</em>.</p>
|
||
<p>We’ve also already seen other ways to write the same data:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>CSV PPRINT JSON
|
||
shape,flag,index shape flag index [
|
||
circle,1,24 circle 1 24 {
|
||
square,0,36 square 0 36 "shape": "circle",
|
||
"flag": 1,
|
||
"index": 24
|
||
},
|
||
DKVP XTAB {
|
||
shape=circle,flag=1,index=24 shape circle "shape": "square",
|
||
shape=square,flag=0,index=36 flag 1 "flag": 0,
|
||
index 24 "index": 36
|
||
}
|
||
shape square ]
|
||
flag 0
|
||
index 36
|
||
</pre></div>
|
||
</div>
|
||
<p>Anything we can do with CSV input data, we can do with any other format input data. And you can read from one format, do any record-processing, and output to the same format as the input, or to a different output format.</p>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<h3><a href="index.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">Miller by example</a><ul>
|
||
<li><a class="reference internal" href="#obtaining-miller">Obtaining Miller</a></li>
|
||
<li><a class="reference internal" href="#miller-verbs">Miller verbs</a></li>
|
||
<li><a class="reference internal" href="#tbf">TBF</a></li>
|
||
<li><a class="reference internal" href="#choices-for-printing-to-files">Choices for printing to files</a></li>
|
||
<li><a class="reference internal" href="#id1">TBF</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<div role="note" aria-label="source link">
|
||
<h3>This Page</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="_sources/miller-by-example.rst.txt"
|
||
rel="nofollow">Show Source</a></li>
|
||
</ul>
|
||
</div>
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" />
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>$('#searchbox').show(0);</script>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="nav-item nav-item-0"><a href="index.html">Miller 6.0.0-alpha documentation</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Miller by example</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2020, John Kerl.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
|
||
</div>
|
||
</body>
|
||
</html> |