find
The find command is used to filter rows in the input depending on CSV field values. In this way, it is very similar to the UNIX grep command but, unlike grep, understands the CSV format, and can apply the search to specific CSV fields. To simulate grep -v, see the remove command.
See also: edit, remove
Flag |
Req'd? |
Description |
-f fields |
No |
Specifies a comma-separated list of field indices identifying the fields in the input which will be used by the filter. If the -f flag is not specified, all fields are used. |
-e expr |
No |
Specifies a regular expression which will be compared against the fields specified by the -f flag. If the expression matches, the row will appear in the command output. You can specify more than one expression, by using multiple -e flags, in which case the row will be output if any of them match. Note that at least one of -e -ei -s -si -r -fc or -l flags must be specified |
-s str |
No |
As for -e, but do not treat str as regular expression. |
-ei expr |
No |
As for -e, but ignore case when performing comparison. |
-si str |
No |
As for -ei, but do not treat str as regular expression. |
-n |
No |
Instead of outputting matched records outputs the number of matches . This is useful when using CSVfix in scripts. |
-r range |
No |
Specifies a range to search for. For example: |
-l length |
No |
Search for fields having specific lengths. Lengths may be specified as a single number or a range: |
-fc count |
No |
Specify that only rows with a certain number of fields will be found. The field count can be specified as a single number or a range for example: |
-if expr |
No |
Evaluates the expression expr using the same expression language used by the eval command for each row. If the expression evaluates to true, the remaining options if any are applied, otherwise the row is treated as not found.
|
The following example lists British cities in the cities.csv file:
csvfix find -e 'GB' -f 2 data/cities.csv
which produces:
"London","GB"
"Edinburgh","GB"
This further example lists only the entry for Paris (length 5) from the same data;
csvfix find -l 5 -f 1 data/cities.csv
This example lists all people in names.csv who's first name is longer than 5 characters:
csvfix find -if 'len($1)>5' data/names.csv
Created with the Personal Edition of HelpNDoc: Produce online help for Qt applications