POKI_PUT_TOC_HERE

<h1>Examples</h1>

POKI_RUN_COMMAND{{mlr --usage-data-format-examples}}HERE

<h1>DKVP: Key-value pairs</h1>
Miller&rsquo;s default file format is DKVP, for <b>delimited key-value pairs</b>. Example:

POKI_RUN_COMMAND{{mlr cat data/small}}HERE

Such data are easy to generate, e.g. in Ruby with
POKI_CARDIFY(puts "host=#{hostname},seconds=#{t2-t1},message=#{msg}")HERE
POKI_CARDIFY(puts mymap.collect{|k,v| "#{k}=#{v}"}.join(','))HERE
or <tt>print</tt> statements in various languages, e.g.
POKI_CARDIFY(echo "type=3,user=$USER,date=$date\n";)HERE
POKI_CARDIFY(logger.log("type=3,user=$USER,date=$date\n");)HERE

<p/>Fields lacking an IPS will have positional index (starting at 1) used as
the key, as in NIDX format. For example, <tt>dish=7,egg=8,flint</tt> is parsed
as <tt>"dish" =&gt; "7", "egg" =&gt; "8", "3" =&gt; "flint"</tt> and
<tt>dish,egg,flint</tt> is parsed as <tt>"1" =&gt; "dish", "2" =&gt; "egg", "3"
=&gt; "flint"</tt>.

<p/> As discussed in POKI_PUT_LINK_FOR_PAGE(record-heterogeneity.html)HERE,
Miller handles changes of field names within the same data stream. But using
DKVP format this is particularly natural. One of my favorite use-cases for
Miller is in application/server logs, where I log all sorts of lines such as

<p/>
<div class="pokipanel">
<pre>
resource=/path/to/file,loadsec=0.45,ok=true
record_count=100, resource=/path/to/file
resource=/some/other/path,loadsec=0.97,ok=false
</pre>
</div>
<p/>

etc. and I just log them as needed. Then later, I can use <tt>grep</tt>, <tt>mlr --opprint group-like</tt>, etc.
to analyze my logs.

<p/>See POKI_PUT_LINK_FOR_PAGE(reference.html)HERE regarding how to specify separators other than
the default equals-sign and comma.

<h1>NIDX: Index-numbered (toolkit style)</h1>

With <tt>--inidx --ifs ' ' --repifs</tt>, Miller splits lines on whitespace and
assigns integer field names starting with 1. This recapitulates Unix-toolkit
behavior.

<p/> Example with index-numbered output:

<table><tr> <td>
POKI_RUN_COMMAND{{cat data/small}}HERE
</td> <td>
POKI_RUN_COMMAND{{mlr --onidx --ofs ' ' cat data/small}}HERE
</td> </tr></table>

<p/> Example with index-numbered input:

<table><tr> <td>
POKI_RUN_COMMAND{{cat data/mydata.txt}}HERE
</td> <td>
POKI_RUN_COMMAND{{mlr --inidx --ifs ' ' --odkvp cat data/mydata.txt}}HERE
</td> </tr></table>

<p/> Example with index-numbered input and output:

<table><tr> <td>
POKI_RUN_COMMAND{{cat data/mydata.txt}}HERE
</td> <td>
POKI_RUN_COMMAND{{mlr --nidx --fs ' ' --repifs cut -f 2,3 data/mydata.txt}}HERE
</td> </tr></table>

<h1>CSV/TSV/etc.</h1>
When <tt>mlr</tt> is invoked with the <tt>--csv</tt> or <tt>--csvlite</tt> option,
key names are found on the first record and values are taken from subsequent
records.  This includes the case of CSV-formatted files.  See
POKI_PUT_LINK_FOR_PAGE(record-heterogeneity.html)HERE for how Miller handles
changes of field names within a single data stream.

<p/> Miller has record separator <tt>RS</tt> and field separator <tt>FS</tt>,
just as <tt>awk</tt> does.  For TSV, use <tt>--fs tab</tt>; to convert TSV to
CSV, use <tt>--ifs tab --ofs comma</tt>, etc.  (See also
POKI_PUT_LINK_FOR_PAGE(reference.html)HERE.)

<p/>Miller&rsquo;s <tt>--csv</tt> flag supports RFC-4180 CSV (<a href="https://tools.ietf.org/html/rfc4180">
https://tools.ietf.org/html/rfc4180</a>). This includes CRLF line-terminators by default, regardless
of platform. You can use <tt>mlr --csv --rs lf</tt> for native Un*x (LF-terminated) CSV files.

<p/>The RFC says, somewhat briefly, that &ldquo;there may be a header
line&rdquo;. Miller&rsquo;s <tt>--implicit-csv-header</tt> option allows you to
read CSV data which lacks a header line, applying column labels <tt>1</tt>,
<tt>2</tt>, <tt>3</tt>, etc. for you. You may also use Miller&rsquo;s
<tt>label</tt> to replace those numerical column names with labels of your
choosing.

<p/>Here are the differences between CSV and CSV-lite:

<ul>

<li/>CSV supports <a href="https://tools.ietf.org/html/rfc4180">
RFC-4180</a>)-style double-quoting, including the ability to have commas and/or
CR-LF line-endings contained within an input field; CSV-lite does not.

<li/>Default record separator for CSV is CR-LF; default record separator for
CSV-lite is LF.

<li/>CSV does not allow heterogeneous data; CSV-lite does (see also <a
href="record-heterogeneity.html">here</a>).

<li/>The CSV-lite input-reading code is more efficient than the CSV
input-reader.

</ul>

<p/>Here are things they have in common:

<ul>

<li/>The ability to specify record/field separators other than the default,
e.g. CR-LF vs. LF, or tab instead of comma for TSV, and so on.

<li/>The <tt>--implicit-csv-header</tt> flag for input and the
<tt>--headerless-csv-output</tt> flag for output.

</ul>

<h1>PPRINT: Pretty-printed tabular</h1>
Miller&rsquo;s pretty-print format is like CSV, but column-aligned.  For example, compare

<table><tr><td>
POKI_RUN_COMMAND{{mlr --ocsv cat data/small}}HERE
</td>
<td>
POKI_RUN_COMMAND{{mlr --opprint cat data/small}}HERE
</td></tr></table>

Note that while Miller is a line-at-a-time processor and retains input lines in
memory only where necessary (e.g. for sort), pretty-print output requires it to
accumulate all input lines (so that it can compute maximum column widths)
before producing any output. This has two consequences: (a) pretty-print output
won&rsquo;t work on <tt>tail -f</tt> contexts, where Miller will be waiting for
an end-of-file marker which never arrives; (b) pretty-print output for large
files is constrained by available machine memory.

<p/> See POKI_PUT_LINK_FOR_PAGE(record-heterogeneity.html)HERE for how Miller
handles changes of field names within a single data stream.

<h1>XTAB: Vertical tabular</h1>

<p/>This is perhaps most useful for looking a very wide and/or multi-column
data which causes line-wraps on the screen (but see also <a
href="https://github.com/twosigma/ngrid">https://github.com/twosigma/ngrid</a>
for an entirely different, very powerful option). Namely:

<table><tr> <td>
POKI_INCLUDE_ESCAPED(system-file-opprint-example.txt)HERE
</td></tr> <tr><td>
POKI_INCLUDE_ESCAPED(system-file-oxtab-example.txt)HERE
</td> </tr></table>

