Select records based on the specified row numbers. Note that row number starts at 0 (the first row of data starts at row 0 excluding the row of field names). Define the row numbers at from= and to= parameters (and size= parameter in some instances).
mbest [s=] [from=] [to=|size=] [k=] [u=] [-r] [i=] [o=] [-nfn] [-nfno] [-x] [-q] [--help] [--version]
s= After sorted by specified field(s) (multiple fields can be specified), the rows are selected. s= parameter is required if -q option is not specified. from= Define the start of row number (integers greater than 0) [default value: 0] to= Define the end of row number (integers greater than 0) [default value: 0] Where [value of from= ] [value of to=] . size= Number of rows to select [default value: 1] to= and size= cannot be specified at the same time. k= Key field (accept multiple key fields) [aggregate key break processing] Records with same key values will be selected based on the defined rows at from=,to=,size=. -x,-nfn options can be used to specify the field number (0〜). u= Output file of unmatched records. Unmatched records the do not match the criteria is written to the defined file. -r Reverse selection Select the rows other than the ones defined at the parameter from=,to=(size=).
This example assumed that the "quantity" and "amount" fields are sorted from the largest value (descending order). Records are selected from the first row (line 0) by default if from=,to=,size= parameters are not specified.
$ more dat1.csv Customer,Quantity,Amount A,20,5200 B,18,4000 C,15,3500 D,10,2000 E,3,800 $ mbest s=Quantity%nr,Amount%nr i=dat1.csv o=rsl1.csv #END# kgbest i=dat1.csv o=rsl1.csv s=Quantity%nr,Amount%nr $ more rsl1.csv Customer,Quantity%0nr,Amount%1nr A,20,5200
After sorting by "customers", select 3 rows from the first row (line 0).
$ mbest s=Customer from=0 size=3 i=dat1.csv o=rsl2.csv #END# kgbest from=0 i=dat1.csv o=rsl2.csv s=Customer size=3 $ more rsl2.csv Customer%0,Quantity,Amount A,20,5200 B,18,4000 C,15,3500
Without sorting (in the original order), select from line 0 to line 1.
$ mbest -q from=0 to=1 i=dat1.csv o=rsl3.csv #END# kgbest -q from=0 i=dat1.csv o=rsl3.csv to=1 $ more rsl3.csv Customer,Quantity,Amount A,20,5200 B,18,4000
Select records other than customers’ first visit to store. Save the records of customers’ first visit to the file fvd.csv.
$ more dat2.csv Customer,Date,Amount A,20081201,10 A,20081207,20 A,20081213,30 B,20081002,40 B,20081209,50 $ mbest s=Customer,Date k=Customer -r u=fvd.csv i=dat2.csv o=rsl4.csv #END# kgbest -r i=dat2.csv k=Customer o=rsl4.csv s=Customer,Date u=fvd.csv $ more rsl4.csv Customer,Date,Amount A,20081207,20 A,20081213,30 B,20081209,50 $ more fvd.csv Customer,Date,Amount A,20081201,10 B,20081002,40
msel : The line() function can be specified in the condition parameter to carry out similar processing functions.
muniq : Returns unique values in key field.
mselnum :Select rows within a numeric range.