DFget

DFget — Get specified data fields from each record in an input file and write them to an output file

Synopsis

DFget [-w] [-i delim] [-o delim] [-f #] {#, #-#}

Description

DFget reads records from the standard input and writes records to the standard output. Each input record is assumed to contain one or more fields delimited by the input delimiter. For each input record DFget applies the field specification string to create a new output record that is written to the standard output.

The field specification is constructed from one or more field specifiers. Each field specifier can be a single field number, a range of field numbers or a string.

One or more constant string fields can be inserted in output records. String fields can contain numbers and characters, and can also contain blank spaces. If the constant string field is a number (or begins with a number) it must be enclosed in a pair of single-double quotes (e.g. '"55"') or double-single quotes (e.g. "'55'"). This prevents DFget from interpreting those numeric strings as field specifiers.

Only those fields included in the field specification will be written to the new output record. Fields in the output record are delimited by the output delimiter and are written in the order given in the field specification.

The field number NF can be used to reference the last field in a record, and NF-n can be used to reference the nth from last field in a record.

DFget is a convenient way to extract fields from exported database records. Remember to first export the desired data files using DFexport.rpc.

Combining the tools DFexport.rpc, DFget, and DFimport.rpc is a powerful way to manipulate data.

Options

-w

warn about records that are too short to contain one or more of the requested fields. By default, no warnings are written and the requested fields that are not available are filled with blanks.

-i delim

the specified character is the field delimiter in the input records. The default is |.

-o delim

use the specified character as the field delimiter in the output records. The default is |.

-f #

skip any records that do not contain the specified number of fields.

#, #-#

the fields to retrieve from each record, and any constant values that are to be inserted (required).

Exit Status

DFget exits with one of the following statuses:

0

The command was successful.

36

The required command-line arguments were not present or were incorrectly specified.

Examples

Example 3.48. Retrieving specified fields from input records

Consider the following two line input file:

102|2|2|0101|gh|2|mellaril|t|100|1|90/03/01|0|
102|2|9|0101|bc|2|noctec|c|500|1|90/07/12|0|

To retrieve fields 1, 4 through 7, a constant string and the last 2 fields from each record, with a colon as the output delimiter, DFget could be used as follows:

% DFget -i '|' -o ':' 1 4~7 "'12 gm'" NF-1 NF < infile
102:0101:gh:2:mellaril:12 gm:90/03/01:0
102:0101:bc:2:noctec:12 gm:90/07/12:0


See Also

DFexport.rpc