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



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

CSV Files Filter

20210128 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
red,circle,1,16,13.8103,2.9010
yellow,circle,1,73,63.9785,4.2370
yellow,circle,1,87,63.5058,8.3350

Select rows using the verb filter on a character field:

$ mlr --csv filter '$color == "yellow"' example.csv
color,shape,flag,index,quantity,rate
yellow,triangle,1,11,43.6498,9.8870
yellow,circle,1,73,63.9785,4.2370
yellow,circle,1,87,63.5058,8.3350

Select rows using multiple filters (to limit the output):

$ mlr --csv filter '$color == "yellow"' then filter 'NR < 2' example.csv
color,shape,flag,index,quantity,rate
yellow,triangle,1,11,43.6498,9.8870

We can also ignore specific columns:

$ mlr --csv filter '$color == "yellow"' then put 'unset $index' example.csv
color,shape,flag,quantity,rate
yellow,triangle,1,43.6498,9.8870
yellow,circle,1,63.9785,4.2370
yellow,circle,1,63.5058,8.3350


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.