mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-21 02:23:20 +00:00
neaten
This commit is contained in:
parent
559fb13785
commit
df4116bf33
5 changed files with 101 additions and 5 deletions
|
|
@ -7,7 +7,6 @@
|
|||
================================================================
|
||||
FEATURES/+
|
||||
|
||||
!! move lrec_parsers -> readers severally
|
||||
!! mmap impl: csv
|
||||
!! then: --mmap by default
|
||||
!! mmap/stdio UTs; maybe run all cases with --mmap and again with --no-mmap
|
||||
|
|
|
|||
|
|
@ -46,8 +46,10 @@ Its domain-specific languages are limited to the <tt>filter</tt> and
|
|||
functions are stream functions. This means <tt>NF</tt>, <tt>NR</tt>, etc.
|
||||
change from one line to another, <tt>$x</tt> is a label for field <tt>x</tt> in
|
||||
the current record, and the input to <tt>sqrt($x)</tt> changes from one record
|
||||
to the next. Miller doesn’t let you set, say, <tt>sum=0</tt> and then
|
||||
update that on each record.
|
||||
to the next. Miller doesn’t let you set <tt>sum=0</tt> before
|
||||
records are read, then update that sum on each record, then print its value at the
|
||||
end. (However, do see <tt>mlr step -a rsum</tt> in the
|
||||
POKI_PUT_LINK_FOR_PAGE(reference.html)HERE) page.)
|
||||
|
||||
<li/> Miller is faster than <tt>awk</tt>, <tt>cut</tt>, and so on (depending on
|
||||
platform; see also POKI_PUT_LINK_FOR_PAGE(performance.html)HERE). In
|
||||
|
|
|
|||
|
|
@ -39,6 +39,40 @@ Miller’s default file format is DKVP, for <b>delimited key-value pairs</b>
|
|||
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/> 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>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
|
||||
behavor.
|
||||
|
||||
<p/> Example with index-numbered output:
|
||||
<pre>
|
||||
puts mymap.collect{|k,v| "#{k}=#{v}"}.join(',')
|
||||
</pre>
|
||||
|
|
|
|||
|
|
@ -170,8 +170,10 @@ Its domain-specific languages are limited to the <tt>filter</tt> and
|
|||
functions are stream functions. This means <tt>NF</tt>, <tt>NR</tt>, etc.
|
||||
change from one line to another, <tt>$x</tt> is a label for field <tt>x</tt> in
|
||||
the current record, and the input to <tt>sqrt($x)</tt> changes from one record
|
||||
to the next. Miller doesn’t let you set, say, <tt>sum=0</tt> and then
|
||||
update that on each record.
|
||||
to the next. Miller doesn’t let you set <tt>sum=0</tt> before
|
||||
records are read, then update that sum on each record, then print its value at the
|
||||
end. (However, do see <tt>mlr step -a rsum</tt> in the
|
||||
<a href="reference.html">Reference</a>) page.)
|
||||
|
||||
<li/> Miller is faster than <tt>awk</tt>, <tt>cut</tt>, and so on (depending on
|
||||
platform; see also <a href="performance.html">Performance</a>). In
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ Miller commands were run with pretty-print-tabular output format.
|
|||
• <a href="#Pretty-printed">Pretty-printed</a><br/>
|
||||
• <a href="#Key-value_pairs">Key-value pairs</a><br/>
|
||||
• <a href="#Index-numbered_(toolkit_style)">Index-numbered (toolkit style)</a><br/>
|
||||
• <a href="#Index-numbered_(toolkit_style)">Index-numbered (toolkit style)</a><br/>
|
||||
• <a href="#Vertical_tabular">Vertical tabular</a><br/>
|
||||
</div>
|
||||
<p/>
|
||||
|
|
@ -173,6 +174,64 @@ a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
|
|||
<p/>
|
||||
|
||||
Such data are easy to generate, e.g. in Ruby with
|
||||
<p/>
|
||||
<div class="pokipanel">
|
||||
<pre>
|
||||
puts "host=#{hostname},seconds=#{t2-t1},message=#{msg}"
|
||||
</pre>
|
||||
</div>
|
||||
<p/>
|
||||
<p/>
|
||||
<div class="pokipanel">
|
||||
<pre>
|
||||
puts mymap.collect{|k,v| "#{k}=#{v}"}.join(',')
|
||||
</pre>
|
||||
</div>
|
||||
<p/>
|
||||
or <tt>print</tt> statements in various languages, e.g.
|
||||
<p/>
|
||||
<div class="pokipanel">
|
||||
<pre>
|
||||
echo "type=3,user=$USER,date=$date\n";
|
||||
</pre>
|
||||
</div>
|
||||
<p/>
|
||||
<p/>
|
||||
<div class="pokipanel">
|
||||
<pre>
|
||||
logger.log("type=3,user=$USER,date=$date\n");
|
||||
</pre>
|
||||
</div>
|
||||
<p/>
|
||||
|
||||
<p/> As discussed in <a href="record-heterogeneity.html">Record-heterogeneity</a>, 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 <a href="reference.html">Reference</a> regarding how to specify separators other than
|
||||
the default equals-sign and comma.
|
||||
|
||||
<a id="Index-numbered_(toolkit_style)"/><h1>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
|
||||
behavor.
|
||||
|
||||
<p/> Example with index-numbered output:
|
||||
<pre>
|
||||
puts mymap.collect{|k,v| "#{k}=#{v}"}.join(',')
|
||||
</pre>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue