csvfile
Queries data from a CSV file.
Command properties
| Item | Description |
|---|---|
| Command type | Driver query |
| Required permission | Local file read permission |
| License usage | Counted |
| Parallel execution | Not supported |
| Distributed execution | Not supported |
Syntax
Options
offset=INT- Number of records to skip. Counted from after the header row.
limit=INT- Maximum number of records to retrieve.
tab={t|f}- When set to
t, uses a tab character as the delimiter. When omitted or set tof, uses a comma (,) as the delimiter. strict={t|f}- When set to
t, parses strictly according to RFC 4180. maxcol=INT- Maximum number of columns. Columns exceeding this count are not assigned as fields.
rest={t|f}- When set to
t, records columns exceedingmaxcolin the_restfield. cs=STR- Character encoding of the CSV file. Default:
utf-8
Target
PATH- CSV file path. Use a wildcard (
*) to specify multiple files. Files with a.gzextension are automatically decompressed.
Output fields
| Field | Type | Description |
|---|---|---|
| (header columns) | string | Field names and values defined in the CSV header |
| _file | string | Source file name |
| _rest | string | Columns exceeding maxcol (output only when the rest=t option is used) |
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 10802 | - | No file path is specified. |
| 10800 | - | The file does not exist or cannot be read. |
| 10801 | - | The parent directory does not exist or cannot be read. |
| 10803 | - | File access is denied. |
Description
The csvfile command reads the specified CSV file and returns each row as a record. The first line of the file is treated as the header and field names are assigned automatically.
When a data row has more columns than the header, the extra columns are returned with field names in the format column0, column1, and so on. When you use the maxcol and rest=t options together, the extra columns are collected and returned in the _rest field.
Files containing a BOM (Byte Order Mark) are automatically detected.
Examples
-
Querying a CSV file
csvfile /opt/logpresso/data/sample.csvRetrieves all data from the specified CSV file.
-
Querying a tab-delimited file with a limit of 100 records
csvfile tab=t limit=100 /opt/logpresso/data/sample.tsvRetrieves up to 100 records using a tab character as the delimiter.
-
Querying an EUC-KR encoded file
csvfile cs=euc-kr /opt/logpresso/data/legacy.csvQueries a CSV file encoded in EUC-KR.