ffe

Langue: en

Autres versions - même langue

Version: 2007-05-22 (debian - 07/07/09)

Section: 1 (Commandes utilisateur)

NAME

ffe - flat file extractor

SYNOPSIS

ffe [options]...

DESCRIPTION

ffe is a program for extracting fields from flat file records and displaying them in different formats. ffe relies on the configuration file to control input file structure and the output format.

OPTIONS

ffe accepts the following options:
-c, --configuration=file
Read the configuration from file, default is ~/.fferc.
-s, --structure=STRUCTURE
Use the structure STRUCTURE for input file.
-p, --print=FORMAT
Use output format FORMAT for printing. All printing can be suppressed using format 'no'.
-o, --output=NAME
Write output to NAME instead of standard output.
-f, --field-list=LIST
Print only fields and constants defined in comma separated list LIST.
-e, --expression=EXPRESSION
Print only those records for which the EXPRESSION evaluates to true.
-a, --and
Expressions are combined with logical and, default is logical or.
-v, --invert-match
Print only those records which don't match the expression.
-l, --loose
An invalid input line does not cause program to abort.
-r, --replace=FIELD=VALUE
Replace FIELDs contents with VALUE in output. VALUE can contain same directives as output option data.
-?, --help
List all available options and their meanings.
-V, --version
Show version of program.

All remaining arguments are names of input files; if no input files are specified, then the standard input is read.

Expressions (option -e, --expression)

Expression can be used to select specific records comparing field values.

Expressions can be defined as:

field=value
A record will be selected if the field field is equal to the value value.
field^value
A record will be selected if the field field starts with the value value.
field~value
A record will be selected if the field field contains the value value.
field!value
A record will be selected if the field field is not equal to the value value.
field?value
A record will be selected if the field field matches the regular expression in value.

        

FFE CONFIGURATION

ffe uses the configuration file for extracting fields from the input file and for formatting the fields for output. Every line of the input file is considered as a record. Default configuration file is ~/fferc but another file can be defined with '-c' option.

Configuration file for ffe is a text file. The file may contain empty lines. Commands are case-sensitive. Comments begin with the #-character and end at the end of the line. The string and char definitions can be enclosed in double quotation '"' characters. char is a single character. string and char can contain following escape codes: '\a','\b','\t','\n','\v','\f', '\r', '\"' and '\#'. Character '\' can be escaped as '\\'.

Input file structure

Input file structures are defined with keyword structure:

structure name {options...}

Options must be ended with newline, options are:

type fixed|separated [char] [*]
Fields in the input are fixed length fields or separated by char. If * is defined, multiple sequential separators are considered as one. Default separator is comma.
quoted [char]
Fields may be quoted with char, default quotation mark is double quotation mark '"'. A quotation mark is assumed to be escaped as \char or doubling the mark as charchar in input. Non escaped quotation marks are not preserved in output.
header first|all|no
Controls the occurrence of the header line. Default is no. If set as first or all, the first line of the first input file is considered as header line containing the names of the fields. First means that only the first file has a header, all means means that all files have a header, although the names are still taken from the header of the first file. Header line is handled according the record definition, meaning that the name positions, separators etc. are the same as for fields.
output name
All records belonging this structure are printed according output format name. Default is to use output named as 'default'.
record name {options...}
Defines one record for a structure. A structure can contain several record types.

Record options:

id position string
Identifies a record in the input file. Records are identified by string in input record position position. For fixed length input the position is the byte position of input record and for separated input the position means the position'th field of the input record. Positions start from one. Id's are required only if input structure contains several record types with equal lengths or field counts.
  A record definition can contain several id's, then all id'd must match the input line (id's are combined with logical and).
field name|FILLER|* [length]|* [lookup]
Defines one field in the input structure. length is mandatory for fixed length input structure. Length is also used for printing fields in fixed length format using the %D directive. The order of fields in configuration file is essential, it defines the field order in a record.

If '*' is defined instead of the name, then the 'name' will be the ordinal number of the field, or if the 'header' option has value 'first' or 'all', then the name of the field will taken from the header line (first line of the input).

If lookup is defined then the fields contents is used to make a lookup in lookup table lookup. If length is not needed (separated format) but lookup is needed, use asterisk (*) in place of length definition.

Naming the field as FILLER causes field not to be printed in output.

fields-from record
Fields for this record are the same as for record record.
output name
This record is printed according output-format name. Default is to use output format defined in structure.

Output definitions

There can be several output-definitions in the configuration file. Needed format can be selected with '-p' option. Default format is named as 'default'.

output name|default {options...}
Defines one output format. Output named as 'default' will be used if none is defined for structure or record, or none is given with option '-p'.

Output options:

Pictures in output definition can contain printf-style %-directives:

%f
Name of the input file.
%s
Name of the current structure.
%r
Name of the current record.
%o
Input record number in current file.
%O
Input record number starting from the first file.
%n
Field name.
%t
Field contents, without leading and trailing whitespaces.
%d
Field contents.
%D
Field contents, right padded to the field length (requires length definition for the field).
%l
Value from lookup.
%L
Value from lookup, right padded to the field length (requires length definition for the field).
%e
Does not print anything, causes still the "field empty" check to be performed. Can be used when only the names of non-empty fields should be printed.
%p
Fields start position in a record. For fixed structure this is field's byte position in the input line and for separated structure this is the ordinal number of the field. Starts from one.
%%
Percent sign.
file_header picture
Picture is printed once before file contents.
file_trailer picture
Picture is printed once after file contents.
header picture
If defined, then the header line describing the field names is printed before records. Every field name is printed according the picture using the same separator and fields length as defined for the fields. Picture can contain only %n directive.
data picture
Field contents is printed according picture.
lookup picture
If field is mapped to lookup table, this picture will be used instead of picture from data option. If not defined picture from data will be used.
separator string
All fields are terminated by string, except the last field of the record. Default is not to print separator.
record_header picture
All records are started by picture. Default is not to print header.
record_trailer picture
All records are ended with picture. Default is newline.
justify left|right|char
Fields are left or right justified. char justifies output according the first occurrence of char in the data picture. Default is left.
indent string
Record contents is intended by string. Field contents is intended by two times the string. Default is not to indent.
field-list name1,name2,...
Only fields or constants named as name1,name2,... are printed, same effect as has '-f' option. Default is print all the fields. Fields are also printed in the same order as they are listed.
no-data-print yes|no
When set as no and field-list is defined, suppresses printing of record_header and record_trailer in case where current record contains none of the fields defined in field-list.
field-empty-print yes|no
When set as no, nothing is printed for fields which consist entirely of characters from empty-chars. If none of the fields of a record are printed then the printing of record_trailer is also suppressed. Default is yes.
empty-chars string
string defines a set of characters which define an "empty" field. Default is " \f\n\r\t\v" (space, form-feed, newline, carriage return, horizontal tab and vertical tab)

Lookup definitions

Several lookup tables can be defined in a configuration.
lookup name {options...}
Defines one lookup table.

Lookup options:

search exact|longest
Defines the search type for lookup table.
default-value value
If the lookup is not successful, value from this option is printed for directives %l and %L.
pair key value
One key/value pair for the lookup table.
file name [separator]
Key/value pairs are read from file name. Every line is considered as a key/value pair separated by separator. Default separator is semicolon.

Constants

Additional to input fields constants values can be printed using option -f,--field-list or output option field-list. Constant will be printed using data output option.

Constants are defined as

const name value
when name appears in a field list, value will be printed for every record as name were one of the input fields.

EXAMPLES

Example of fixed length flat file containing fields 'FirstName','LastName' and 'Age':


John Ripper 23
Scott Tiger 45
Mary Moore 41

This file can be printed in XML with the following configuration:

structure personnel {

    type fixed

    output XML

    record person {

        field FirstName 9

        field LastName  13

        field Age 2

    }
}


output XML {

    file_header "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"

    data "<%n>%d</%n>\n"

    record_header "<%r>\n"

    record_trailer "</%r>\n"

    indent " "
}
 
    
        

SEE ALSO

More examples in Texinfo manual. If the info and ffe are properly installed, the command


       info ffe

should give more information.

AUTHOR

Timo Savinen <tjsa@iki.fi>