Skip to main content

## 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: -r 10:50 would search for numbers in the range 10 - 50 inclusive. -r A:C would search for all strings that begin with A, B or C. If both elements of a range are numeric, then numeric searching is performed, and non-numeric values in the input will not be considered part of the range. Multiple ranges may be used, and as with the regex flags an input row will be output if any range matches.
-l length | No | Search for fields having specific lengths. Lengths may be specified as a single number or a range: -l 20 -l 1:10
-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: -fc 3 specifies rows with only three fields. whereas: -fc 2:6 specifies rows containing between two and size fields inclusive.
-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

####