GNU/Linux Desktop Survival Guide
by Graham Williams |
|||||
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 |