Skip to content

DSL filter statements

You can use the filter DSL keyword within the put verb. In fact, the following two are synonymous:

mlr --csv filter 'NR==2 || NR==3' example.csv
color,shape,flag,k,index,quantity,rate
red,square,true,2,15,79.2778,0.0130
red,circle,true,3,16,13.8103,2.9010
mlr --csv put 'filter NR==2 || NR==3' example.csv
color,shape,flag,k,index,quantity,rate
red,square,true,2,15,79.2778,0.0130
red,circle,true,3,16,13.8103,2.9010

The former, of course, is a little easier to type. For another example:

mlr --csv put '@running_sum += $quantity; filter @running_sum > 500' example.csv
color,shape,flag,k,index,quantity,rate
yellow,circle,true,8,73,63.9785,4.2370
yellow,circle,true,9,87,63.5058,8.3350
purple,square,false,10,91,72.3735,8.2430
mlr --csv filter '@running_sum += $quantity; @running_sum > 500' example.csv
color,shape,flag,k,index,quantity,rate
yellow,circle,true,8,73,63.9785,4.2370
yellow,circle,true,9,87,63.5058,8.3350
purple,square,false,10,91,72.3735,8.2430