FFE(1)

πŸ’– NAME πŸ’–

okay so bestie, welcome to FFE(1) β€” this is the manual for ffe, aka the flat file extractor ✨ she's been around, she's iconic, and she has so many options.

🌈 SYNOPSIS 🌈

ffe [options]...

✨ DESCRIPTION ✨

ffe is a program for extracting fields from flat file records and displaying them in different formats πŸ’…. She does not freestyle β€” she relies on the configuration file to control both the input file structure and the output format. So yeah, the config is the main character here, no cap.


πŸŽ€ OPTIONS πŸŽ€

ffe accepts the following options:

  • -c, --configuration=file β€” Read the configuration from file. Default is ~/.fferc.
  • -s, --structure=STRUCTURE β€” Process the input file using the structure STRUCTURE.
  • -p, --print=FORMAT β€” Use output format FORMAT for printing. You can suppress all printing by using the format no. Original data gets printed using the format raw.
  • -o, --output=NAME β€” Write output to NAME instead of standard output.
  • -f, --field-list=LIST β€” Print only the fields and constants in the comma separated list LIST.
  • -e, --expression=EXPRESSION β€” Print only those records for which EXPRESSION evaluates to true.
  • -a, --and β€” Expressions are combined with logical and; the default is logical or.
  • -X, --casecmp β€” Expressions are evaluated case insensitive.
  • -v, --invert-match β€” Print only those records which don't match the expression. the audacity filter 🫢
  • -l, --loose β€” An invalid input line does not cause the program to abort.
  • -r, --replace=FIELD=VALUE β€” Replace FIELD's contents with VALUE in output. VALUE can contain the same directives as the output option data.
  • -d, --debug β€” All invalid input lines are written to the file ffe_error_<pid>.log.
  • -I, --info β€” Show the structure information in the configuration file and exit.
  • -?, --help β€” List all available options and their meanings and exit.
  • -V, --version β€” Show version of program and exit.

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 πŸ‘‘

If the value starts with the string file: then the rest of the value is considered as a file name. Every line in the file is used as a value in comparison. A record will be selected if one or more values evaluates true.

Expression notation:

  • 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 or binary block of the input file is considered as a record. The default configuration file is ~/.fferc, but you can hand her a different file with the -c option.

The 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 the following escape codes: '\a', '\b', '\t', '\n', '\v', '\f', '\r', '\"' and '\#'. The character '\' can be escaped as '\\'.

Command Substitution lets the output of a command replace parts of the configuration file πŸͺ„. Syntax for command substitution is:

`command`

The command is executed and the `command` is substituted with the standard output of the command, with any trailing newlines deleted. Command substitutions may not be nested.

Before executing the command, ffe sets a few environment variables:

  • FFE_STRUCTURE β€” The name of the structure given using -s, --structure.
  • FFE_OUIPUT β€” The name of the output file given using -o, --output. (yes bestie, that's spelled exactly like that in the page β€” copy it character for character πŸ’€)
  • FFE_FORMAT β€” The name of the output format given using -p, --print.
  • FFE_FIRST_FILE β€” The name of the first input file.
  • FFE_FILES β€” A list of all input files.

If a variable is already set, it will not be replaced.

🧚 Input file structure 🧚

Input file structures are specified with the keyword structure:

structure name {options...}

Options must be ended with newline. The options are:

  • type fixed|binary|separated [char] [*] β€” Fields in the input are fixed length text fields, fixed length binary fields, or text fields separated by char. If * is given, multiple sequential separators are considered as one. Default separator is comma.
  • quoted [char] β€” Fields may be quoted with char; the default quotation mark is double quotation mark '"'. A quotation mark is assumed to be escaped as \char or by 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 a header line containing the names of the fields. first means that only the first file has a header; all means that all files have a header, although the names are still taken from the header of the first file. The header line is handled according to the record definition, meaning that the name positions, separators etc. are the same as for the fields.
  • output name β€” All records belonging to this structure are printed according to output format name. Default is to use the 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 and rid position regexp β€” Identifies a record in the input file. Records are identified by the string, or by the regular expression in regexp, at input record position position. For fixed length and binary input, the position is the byte position of the 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 the input structure contains several record types with equal lengths or field counts. Non printable characters can be escaped as \xnn where nn is the hexadecimal value of the character.

A record definition can contain several id's; then all id'd must match the input line (id's are combined with logical and).

In a multi-record binary structure, every record must have at least one id. no id, no entry 🚫
  • field name|FILLER|* [length]|* [lookup]|* [output] β€” Specifies one field in a text input structure. length is mandatory for a fixed length input structure, except for the last field. If the last field of a fixed length input structure has a * in place of length, then the last field can have arbitrary length.

Length is also used for printing fields in fixed length format using the %D or %D directive. The order of fields in the configuration file is essential β€” it specifies the field order in a record.

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

If lookup is given, then the field's 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 the length definition.

If output is given, the field is printed using output output. Use asterisk in place of lookup if lookup is not needed.

Naming the field as FILLER causes the field not to be printed in output πŸ™ˆ.

  • field name|FILLER|* [length]|type [lookup]|* [output] β€” Specifies one field in a binary input structure. All other features are the same as for the text structure, except the type parameter. type specifies field data type and length, and can have the following values:
    • char β€” Printable character.
    • short β€” Short integer having current system length and byte order.
    • int β€” Integer having current system length and byte order.
    • long β€” Long integer having current system length and byte order.
    • llong β€” Long long integer having current system length and byte order.
    • ushort β€” Unsigned short integer having current system length and byte order.
    • uint β€” Unsigned integer having current system length and byte order.
    • ulong β€” Unsigned long integer having current system length and byte order.
    • ullong β€” Unsigned long long integer having current system length and byte order.
    • int8 β€” 8 bit integer.
    • int16_be β€” Big endian 16 bit integer.
    • int32_be β€” Big endian 32 bit integer.
    • int64_be β€” Big endian 64 bit integer.
    • int16_le β€” Little endian 16 bit integer.
    • int32_le β€” Little endian 32 bit integer.
    • int64_le β€” Little endian 64 bit integer.
    • uint8 β€” Unsigned 8 bit integer.
    • uint16_be β€” Unsigned big endian 16 bit integer.
    • uint32_be β€” Unsigned big endian 32 bit integer.
    • uint64_be β€” Unsigned big endian 64 bit integer.
    • uint16_le β€” Unsigned little endian 16 bit integer.
    • uint32_le β€” Unsigned little endian 32 bit integer.
    • uint64_le β€” Unsigned little endian 64 bit integer.
    • float β€” Float having current system length and byte order.
    • float_be β€” Float having current system length and big endian byte order.
    • float_le β€” Float having current system length and little endian byte order.
    • double β€” Double having current system length and byte order.
    • double_be β€” Double having current system length and big endian byte order.
    • double_le β€” Double having current system length and little endian byte order.
    • bcd_be_len β€” Bcd number having length len and nybbles in big endian order.
    • bcd_le_len β€” Bcd number having length len and nybbles in little endian order.
    • hex_be_len β€” Hexadecimal data in big endian order having length len.
    • hex_le_len β€” Hexadecimal data in little endian order having length len.

okay so if you give a length instead of the type, then the field is lowkey assumed to be a printable string that's exactly length long. It prints until it hits length characters or a NULL character, whichever comes first. periodt. πŸ’…

Bcd numbers (bcd_be_len and bcd_le_len) print until len bytes are read or a nybble with hex value f is found. Big endian bcd prints most significant nybble first, then least significant. Little endian bcd prints least significant nybble first, then most significant. And bestie, bytes are ALWAYS read in big endian order. no cap. 🧚

Hexadecimal data (hex_be_len and hex_le_len) prints as hexadecimal values. Big endian data starts from the lower address, little endian from the upper address. it's giving address realness. ✨

  • field-count number β€” same effect as having field * number times. Because length isn't specified, this only works with separated structure. soz. πŸ’€
  • fields-from record β€” the fields for this record are literally the same as for record. copy-paste energy. 🫢
  • output name β€” this record is printed according to output format name. Default is to use the output format specified in the structure. periodt. 🌸
  • level number [element_name|*] [group_name] β€” level can be used if the contents of a file should be printed as a hierarchical multi-level nested form document. Use * instead of the element name if it's not needed. number is the level of the record, starting from 1 (highest level). element_name is the name for the record, and group_name groups records in the same and lower levels. Only number is mandatory, bestie. πŸ‘‘
  • record-length strict|minimum β€” controls how strict the record length matching is.
    • strict β€” input record length and field count must match the record definition to get processed. This is the default value. so strict, much wow. πŸ’…
    • minimum β€” input record length and field count can be the same or longer as defined for the record. The rest of the input line is ignored. lowkey chill. πŸ¦‹

✨ Output definitions ✨

There can be several output definitions in the configuration file. Format can be selected with the -p option. The default format is named 'default'. iconic. πŸ’–

  • output name|default {options...} β€” defines one output format. The output named 'default' will be used if none is given for structure or record, or if none is given with option -p. There are two predefined output formats: no and raw. no suppresses all printing, and raw prints the original input data. slay. πŸ”₯

🌈 Output options 🌈

Pictures in an output definition can contain printf-style %-directives. here's the tea: β˜•

  • %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. πŸ”’
  • %i β€” byte offset of the current record in the current file. Starts from zero. 0️⃣
  • %I β€” byte offset of the current record starting from the first file. Starts from zero. 0️⃣
  • %n β€” field name. 🏷️
  • %t β€” field contents, without leading and trailing whitespaces. βœ‚οΈ
  • %d β€” field contents. Binary integer is printed as a decimal value. Floating point number is printed in the style [-]ddd.ddd, where the number of digits after the decimal-point character is 6. Bcd number is printed as a decimal number and hexadecimal data as consecutive hexadecimal values. πŸ”’
  • %D β€” field contents, right padded to the field length (requires length definition for the field). ➑️
  • %C β€” field contents, right padded to the field length (requires length definition for the field). Output field is cut if input field is longer that field length. βœ‚οΈ
  • %x β€” unsigned hexadecimal value of a binary integer. Other fields are printed using directive %d. πŸ”’
  • %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. 1️⃣
  • %h β€” hexadecimal dump of a field. Byte values are printed as consecutive xnn values, where the nn is the hexadecimal value of a byte. Data is printed before any endian conversion. 🧬
  • %g β€” group name given by the keyword group_name in record definition. πŸ‘₯
  • %m β€” element name given by the keyword element_name in record definition. 🏷️
  • %% β€” 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 specified, 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 to picture. πŸ“Š
  • lookup picture β€” if field is mapped to lookup table, this picture will be used instead of picture from data option. If not given, then 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 β€” picture is printed before the record content. Default is not to print header. πŸ“
  • record_trailer picture β€” picture is printed after the record content. Default is newline. πŸ“
  • justify left|right|char β€” fields are left or right justified. char justifies output according to 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 to 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 given, suppresses printing of record_header and record_trailer in case where current record contains none of the fields specified 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 specifies 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). πŸ•³οΈ
  • output-file file β€” output is written to file instead of the default output. If - is given the standard output is used. πŸ“
  • group_header string β€” if a record has a level and group name defined, string is printed before the first record in the same group or if the group name has changed in the same level. πŸ‘₯
  • group_trailer string β€” if a record has a level and group name defined, string is printed after the records in lower levels or if the group name has changed in the same level or if a higher level record is found. πŸ‘₯
  • element_header string β€” if record has a level and header name defined, string is printed before the records contents. 🏷️
  • element_header string β€” if record has a level and header name defined, string is printed after the records contents. (yes, it's listed twice, that's what the manpage says, not me πŸ™ˆ) 🏷️
  • hex-caps yes|no β€” print hexadecimal numbers in capital letters. Default is no. πŸ” 

πŸŽ€ Lookup definitions πŸŽ€

  • lookup name {options...} β€” defines one lookup table. that's it, that's the tweet. πŸ’…

πŸ” Lookup options: πŸ”

  • search exact|longest β€” the search type for lookup table. πŸ”Ž
  • default-value value β€” value is printed if the lookup is not successful. 🚫
  • 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 specified as

  • const name value β€” when the name appears in a field list, value will be printed for every record as the name were one of the input fields. πŸ’Ž

🌟 Input Preprocessor 🌟

It is possible to define an input preprosessor for ffe. An input preprocessor is simply an executable program which writes the contents of the input file to standard output which will be read by ffe. If the input preprosessor does not write any characters on its standard output, then ffe uses the original file. no cap. 🧚

To set up an input preprocessor, set the FFEOPEN environment variable to a command line which will invoke your input preprocessor. This command line should include one occurrence of the string %s, which will be replaced by the input filename when the input preprocessor command is invoked. periodt. πŸ”§

The input preprocessor is not used if ffe is reading standard input. soz. 🚫


✨ 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. iykyk. πŸ’…

πŸ’– AUTHOR πŸ’–

Timo Savinen <tjsa@iki.fi >


This page was brought to you by Timo Savinen, dated 2011-04-06, for FFE(1). Stay slay, bestie! πŸ’…βœ¨