Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go

CSV Files

20200421 The command mlr from the package miller is a powerfull command line tool for working with csv, tsv, and tabular JSON files.

A verb is required to specify an action. Here we simply cat the file:

$ mlr cat example.csv
1=color,2=shape,3=flag,4=index,5=quantity,6=rate
1=yellow,2=triangle,3=1,4=11,5=43.6498,6=9.8870
...

Note that the input is a csv file.

$ mlr --icsv cat example.csv
color,shape,flag,index,quantity,rate
yellow,triangle,1,11,43.6498,9.8870
red,square,1,15,79.2778,0.0130
...

Pretty print the output.

$ mlr --icsv --opprint cat example.csv
color  shape    flag index quantity rate
yellow triangle 1    11    43.6498  9.8870
red    square   1    15    79.2778  0.0130
...

Select fields from the file using the verb cut:

$ mlr --csv --opprint cut -f flag,shape example.csv
shape    flag
triangle 1
square   1
...

Order the fields as specified:

$ mlr --icsv --opprint cut -o -f flag,shape example.csv
flag shape
1    triangle
1    square
...

Select rows using the verb filter with both input and output as csv:

$ mlr --csv filter '$flag == 1' example.csv
color,shape,flag,index,quantity,rate
yellow,triangle,1,11,43.6498,9.8870
red,square,1,15,79.2778,0.0130

Further details at https://johnkerl.org/miller/doc/.


Support further development by purchasing the PDF version of the book.
Other online resources include the Data Science Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 1995-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.