Forrest logo
back to the mlr tool

mlr:tldr:2f08d

mlr: Convert CSV to JSON, performing calculations and display those calculations.
$ mlr --icsv --ojson put '$${newField1} = $${oldFieldA}/$${oldFieldB}' ${example-csv}
try on your machine

This command is using the mlr (Miller) tool to transform a CSV file into a JSON format. Let's break down the command step by step:

  1. mlr: This is the command to invoke the Miller tool.

  2. --icsv: This flag specifies that the input file is in CSV format.

  3. --ojson: This flag instructs the Miller tool to generate JSON output.

  4. put: This is a Miller verb that allows you to create or modify fields based on defined expressions.

  5. $${newField1} = $${oldFieldA}/$${oldFieldB}: This is the expression that defines the computation for the new field, newField1. It calculates the division of oldFieldA by oldFieldB and assigns the result to newField1. The double curly braces ($${}) are used to indicate that the field names are variables.

  6. ${example-csv}: This is the input file name or path, in this case, example-csv.

To summarize, the command takes a CSV file, calculates the division of two fields (oldFieldA divided by oldFieldB), assigns the result to a new field called newField1, and outputs the resulting JSON representation of the modified file.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the mlr tool