csvfile

Queries data from a CSV file.

Command properties

ItemDescription
Command typeDriver query
Required permissionLocal file read permission
License usageCounted
Parallel executionNot supported
Distributed executionNot supported

Syntax

csvfile [offset=INT] [limit=INT] [tab={t|f}] [strict={t|f}] [maxcol=INT] [rest={t|f}] [cs=STR] PATH

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 to f, 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 exceeding maxcol in the _rest field.
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 .gz extension are automatically decompressed.

Output fields

FieldTypeDescription
(header columns)stringField names and values defined in the CSV header
_filestringSource file name
_reststringColumns exceeding maxcol (output only when the rest=t option is used)

Error codes

Parse errors
Error codeMessageDescription
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

  1. Querying a CSV file

    csvfile /opt/logpresso/data/sample.csv
    

    Retrieves all data from the specified CSV file.

  2. Querying a tab-delimited file with a limit of 100 records

    csvfile tab=t limit=100 /opt/logpresso/data/sample.tsv
    

    Retrieves up to 100 records using a tab character as the delimiter.

  3. Querying an EUC-KR encoded file

    csvfile cs=euc-kr /opt/logpresso/data/legacy.csv
    

    Queries a CSV file encoded in EUC-KR.