Skip to main content

## read_dsv

The read_dsv command is used to convert delimiter separated values (DSV) data into CSV. DSV data is most commonly found in the UN*X world - for example, the /etc/passwd file is a DSV file. DSV data consists of values separated by a delimiter character - the vertical bar/pipe character is often used for this. For example, here's the data from the names.csv file in DSV format:
Charles|Dickens|M
Jane|Austen|F
Herman|Melville|M
Flann|O'Brien|M
George|Elliot|F
Virginia|Woolf|F
Oscar|Wilde|M
If a value needs to contain the delimiter, then it must be escaped using a backslash, as must any occurrences of the backslash itself. Here's a file that explains some C++ operators (this is operators.dsv):
asterisk|*|multiplication
equals|=|assignment
pipe|\||bitwise OR
backslash|\\|not a C++ operator
See also: write_dsv

Flag | Req'd? | Description
-f fields | No | Specifies comma-separated list of fields to extract from the DSV data and the order they will appear in the CSV. If not specified, all fields in the DSV are extracted. If a non-existent field is specified, it is treated as though it does exist but is empty.
-s sep | No | Specifies single character separator used in DSV file - the default is the pipe character. You can use this flag to allow reading of the popular tab-separated format by specifying a special tab character as the separator: csvfix read_dsv -s '\t' tabsep.dat Note that the tab character '\t' is the only currently supported "special" character sequence. Spaces are not considered special, so to to read space-separated data, you would use: csvfix read_dsv -s ' ' spacesep.dat
-cm | No | Collapse multiple occurrences of a separator in the DSV input into a single instance. This is useful when reading space-separated files where the fields are separated by a variable number of spaces.
-csv | No | Treat the contents of fields as if they were actually CSV data. If this is not specified, and the fields are double-quoted CSV data, the double-quotes will be escaped on output, resulting in extraneous quoting.

The following example converts the operators.dsv file to CSV:
csvfix read_dsv data/operators.dsv
which produces:
"asterisk","*","multiplication"
"equals","=","assignment"
"pipe","|","bitwise OR"
"backslash","\","not a C++ operator"

Created with the Personal Edition of HelpNDoc: Produce online help for Qt applications

####