diff --git a/doc/10-min.html b/doc/10-min.html index f872126a1..c03661768 100644 --- a/doc/10-min.html +++ b/doc/10-min.html @@ -64,6 +64,8 @@ pageTracker._trackPageview();
10-minute intro
• CSV-file examples
+• JSON-file examples
+• Sorts and stats
• Choices for printing to files
• Other-format examples
• SQL-output examples
@@ -81,7 +83,7 @@ pageTracker._trackPageview();
-

Sample CSV data file:

+

Suppose you have this CSV data file:

@@ -102,7 +104,8 @@ purple,square,0,91,72.3735,8.2430

-

mlr cat is like cat ...

+

mlr cat is like cat -- it passes the data +through unmodified ...

@@ -123,7 +126,7 @@ purple,square,0,91,72.3735,8.2430

-

... but it can also do format conversion (here, to pretty-printed tabular format):

+

... but it can also do format conversion (here, you can pretty-print in tabular format):

@@ -144,8 +147,9 @@ purple square 0 91 72.3735 8.2430

-

mlr head and mlr tail count records rather than lines. The CSV -header is included either way:

+

mlr head and mlr tail count +records rather than lines. Whethere you’re getting the first few records +or the last few, the CSV header is included either way:

@@ -172,8 +176,8 @@ purple,square,0,91,72.3735,8.2430

-

Sort primarily alphabetically on one field, then secondarily -numerically descending on another field:

+

You can sort primarily alphabetically on one field, then +secondarily numerically descending on another field:

@@ -194,7 +198,8 @@ yellow triangle 1 11 43.6498 9.8870

-

Use cut to retain only specified fields, in input-data order:

+

You can use cut to retain only specified fields, in the +same order they appeared in the input data:

@@ -215,7 +220,8 @@ square 0

-

Use cut -o to retain only specified fields, in your specified order:

+

You can also use cut -o to retain only +specified fields in your preferred order:

@@ -236,7 +242,8 @@ flag shape

-

Use cut -x to omit specified fields:

+

You can use cut -x to omit fields you +don’t care about:

@@ -257,7 +264,7 @@ purple 91 72.3735 8.2430

-

Use filter to retain specified records:

+

You can use filter to keep only records you care about:

@@ -282,7 +289,8 @@ red circle 1 16 13.8103 2.9010

-

Use put to add/replace fields which are computed from other fields:

+

You can use put to create new fields which +are computed from other fields:

@@ -345,7 +353,12 @@ purple square NEW 91 72.3735 8.2430

-

JSON output:

+

JSON-file examples

+ +
+ +

OK, CSV and pretty-print are fine. But Miller can also convert between +a few other formats -- let’s take a look at JSON output:

@@ -365,13 +378,12 @@ $ mlr --icsv --ojson put '$ratio = $quantity/$rate; $shape = toupper($shape)' ex

-

JSON output with vertical-formatting flags:

+

Or, JSON output with vertical-formatting flags:

-$ mlr --icsv --ojson --jvstack --jlistwrap tail -n 2 example.csv
-[
+$ mlr --icsv --ojsonx tail -n 2 example.csv
 {
   "color": "yellow",
   "shape": "circle",
@@ -380,7 +392,7 @@ $ mlr --icsv --ojson --jvstack --jlistwrap tail -n 2 example.csv
   "quantity": 63.5058,
   "rate": 8.3350
 }
-,{
+{
   "color": "purple",
   "shape": "square",
   "flag": 0,
@@ -388,16 +400,37 @@ $ mlr --icsv --ojson --jvstack --jlistwrap tail -n 2 example.csv
   "quantity": 72.3735,
   "rate": 8.2430
 }
-]
 

-

Use then to pipe commands together. Also, the --g option for many Miller commands is for group-by: here, head -n -1 -g shape outputs the first record for each distinct value of the -shape field. This means we’re finding the record with highest -index field for each distinct shape field:

+

Sorts and stats

+ +
+ +

Now suppose you want to sort the data on a given column, +and then take the top few in that ordering. You can use Miller’s +then feature to pipe commands together.

+ +

Here are the records with the top three index values:

+ +

+

+
+$ mlr --icsv --opprint sort -f shape -nr index then head -n 3 example.csv
+color  shape  flag index quantity rate
+yellow circle 1    87    63.5058  8.3350
+yellow circle 1    73    63.9785  4.2370
+red    circle 1    16    13.8103  2.9010
+
+
+

+ +

Lots of Miller commands take a -g option +for group-by: here, head -n 1 -g shape outputs the first record +for each distinct value of the shape field. This means we’re +finding the record with highest index field for each distinct +shape field:

@@ -411,25 +444,8 @@ purple triangle 0 65 80.1405 5.8240

-

Statistics can be computed with or without group-by field(s). Also, the first of these two -examples uses --oxtab output format which is a nice alternative to --opprint when you -have lots of columns:

+

Statistics can be computed with or without group-by field(s)

-

-

-
-$ mlr --icsv --oxtab --from example.csv stats1 -a p0,p10,p25,p50,p75,p90,p99,p100 -f rate
-rate_p0   0.013000
-rate_p10  2.901000
-rate_p25  4.237000
-rate_p50  8.243000
-rate_p75  8.591000
-rate_p90  9.887000
-rate_p99  9.887000
-rate_p100 9.887000
-
-
-

@@ -456,6 +472,25 @@ square   purple 1              72.373500    72.373500     72.373500
 

+

If your output has a lot of columns, you can use XTAB +format to line things up vertically for you instead:

+ +

+

+
+$ mlr --icsv --oxtab --from example.csv stats1 -a p0,p10,p25,p50,p75,p90,p99,p100 -f rate
+rate_p0   0.013000
+rate_p10  2.901000
+rate_p25  4.237000
+rate_p50  8.243000
+rate_p75  8.591000
+rate_p90  9.887000
+rate_p99  9.887000
+rate_p100 9.887000
+
+
+

+

Choices for printing to files

diff --git a/doc/content-for-10-min.html b/doc/content-for-10-min.html index 60138fc04..5a8eed0b7 100644 --- a/doc/content-for-10-min.html +++ b/doc/content-for-10-min.html @@ -8,47 +8,53 @@ POKI_PUT_TOC_HERE
-

Sample CSV data file:

+

Suppose you have this CSV data file:

POKI_RUN_COMMAND{{cat example.csv}}HERE -

mlr cat is like cat ...

+

mlr cat is like cat -- it passes the data +through unmodified ...

POKI_RUN_COMMAND{{mlr --csv cat example.csv}}HERE -

... but it can also do format conversion (here, to pretty-printed tabular format):

+

... but it can also do format conversion (here, you can pretty-print in tabular format):

POKI_RUN_COMMAND{{mlr --icsv --opprint cat example.csv}}HERE -

mlr head and mlr tail count records rather than lines. The CSV -header is included either way:

+

mlr head and mlr tail count +records rather than lines. Whethere you’re getting the first few records +or the last few, the CSV header is included either way:

POKI_RUN_COMMAND{{mlr --csv head -n 4 example.csv}}HERE POKI_RUN_COMMAND{{mlr --csv tail -n 4 example.csv}}HERE -

Sort primarily alphabetically on one field, then secondarily -numerically descending on another field:

+

You can sort primarily alphabetically on one field, then +secondarily numerically descending on another field:

POKI_RUN_COMMAND{{mlr --icsv --opprint sort -f shape -nr index example.csv}}HERE -

Use cut to retain only specified fields, in input-data order:

+

You can use cut to retain only specified fields, in the +same order they appeared in the input data:

POKI_RUN_COMMAND{{mlr --icsv --opprint cut -f flag,shape example.csv}}HERE -

Use cut -o to retain only specified fields, in your specified order:

+

You can also use cut -o to retain only +specified fields in your preferred order:

POKI_RUN_COMMAND{{mlr --icsv --opprint cut -o -f flag,shape example.csv}}HERE -

Use cut -x to omit specified fields:

+

You can use cut -x to omit fields you +don’t care about:

POKI_RUN_COMMAND{{mlr --icsv --opprint cut -x -f flag,shape example.csv}}HERE -

Use filter to retain specified records:

+

You can use filter to keep only records you care about:

POKI_RUN_COMMAND{{mlr --icsv --opprint filter '$color == "red"' example.csv}}HERE POKI_RUN_COMMAND{{mlr --icsv --opprint filter '$color == "red" && $flag == 1' example.csv}}HERE -

Use put to add/replace fields which are computed from other fields:

+

You can use put to create new fields which +are computed from other fields:

POKI_RUN_COMMAND{{mlr --icsv --opprint put '$ratio = $quantity / $rate; $color_shape = $color . "_" . $shape' example.csv}}HERE @@ -60,30 +66,49 @@ positional index. Use $[[3]] to access the name of field 3 or POKI_RUN_COMMAND{{mlr --icsv --opprint put '$[[3]] = "NEW"' example.csv}}HERE POKI_RUN_COMMAND{{mlr --icsv --opprint put '$[[[3]]] = "NEW"' example.csv}}HERE -

JSON output:

+

JSON-file examples

+ +
+ +

OK, CSV and pretty-print are fine. But Miller can also convert between +a few other formats -- let’s take a look at JSON output:

POKI_RUN_COMMAND{{mlr --icsv --ojson put '$ratio = $quantity/$rate; $shape = toupper($shape)' example.csv}}HERE -

JSON output with vertical-formatting flags:

+

Or, JSON output with vertical-formatting flags:

-POKI_RUN_COMMAND{{mlr --icsv --ojson --jvstack --jlistwrap tail -n 2 example.csv}}HERE +POKI_RUN_COMMAND{{mlr --icsv --ojsonx tail -n 2 example.csv}}HERE -

Use then to pipe commands together. Also, the --g option for many Miller commands is for group-by: here, head -n -1 -g shape outputs the first record for each distinct value of the -shape field. This means we’re finding the record with highest -index field for each distinct shape field:

+

Sorts and stats

+ +
+ +

Now suppose you want to sort the data on a given column, +and then take the top few in that ordering. You can use Miller’s +then feature to pipe commands together.

+ +

Here are the records with the top three index values:

+ +POKI_RUN_COMMAND{{mlr --icsv --opprint sort -f shape -nr index then head -n 3 example.csv}}HERE + +

Lots of Miller commands take a -g option +for group-by: here, head -n 1 -g shape outputs the first record +for each distinct value of the shape field. This means we’re +finding the record with highest index field for each distinct +shape field:

POKI_RUN_COMMAND{{mlr --icsv --opprint sort -f shape -nr index then head -n 1 -g shape example.csv}}HERE -

Statistics can be computed with or without group-by field(s). Also, the first of these two -examples uses --oxtab output format which is a nice alternative to --opprint when you -have lots of columns:

+

Statistics can be computed with or without group-by field(s)

-POKI_RUN_COMMAND{{mlr --icsv --oxtab --from example.csv stats1 -a p0,p10,p25,p50,p75,p90,p99,p100 -f rate}}HERE POKI_RUN_COMMAND{{mlr --icsv --opprint --from example.csv stats1 -a count,min,mean,max -f quantity -g shape}}HERE POKI_RUN_COMMAND{{mlr --icsv --opprint --from example.csv stats1 -a count,min,mean,max -f quantity -g shape,color}}HERE +

If your output has a lot of columns, you can use XTAB +format to line things up vertically for you instead:

+ +POKI_RUN_COMMAND{{mlr --icsv --oxtab --from example.csv stats1 -a p0,p10,p25,p50,p75,p90,p99,p100 -f rate}}HERE +

Choices for printing to files