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 formatno. Original data gets printed using the formatraw.-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 optiondata.-d,--debugβ All invalid input lines are written to the fileffe_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\charor by doubling the mark ascharcharin input. Non escaped quotation marks are not preserved in output.header first|all|noβ Controls the occurrence of the header line. Default isno. If set asfirstorall, the first line of the first input file is considered as a header line containing the names of the fields.firstmeans that only the first file has a header;allmeans 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 asdefault.record name {options...}β Defines one record for a structure. A structure can contain several record types.
π Record options π
id position stringandrid 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 havingfield*numbertimes. 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 forrecord. copy-paste energy. π«Άoutput nameβ this record is printed according to output formatname. 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.numberis the level of the record, starting from1(highest level).element_nameis the name for the record, andgroup_namegroups records in the same and lower levels. Onlynumberis 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:noandraw.nosuppresses all printing, andrawprints 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 is6. 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 consecutivexnnvalues, where thennis the hexadecimal value of a byte. Data is printed before any endian conversion. π§¬%gβ group name given by the keywordgroup_namein record definition. π₯%mβ element name given by the keywordelement_namein 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%ndirective. π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 fromdataoption. If not given, then picture fromdatawill be used. πseparator stringβ all fields are terminated bystring, 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.charjustifies output according to the first occurrence ofcharin the data picture. Default is left. β¬ οΈβ‘οΈindent stringβ record contents is intended bystring. Field contents is intended by two times thestring. Default is not to indent. πfield-list name1,name2,...β only fields or constants named asname1,name2,...are printed, same effect as has-foption. 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 asnoandfield-listis given, suppresses printing ofrecord_headerandrecord_trailerin case where current record contains none of the fields specified infield-list. π«field-empty-print yes|noβ when set asno, nothing is printed for fields which consist entirely of characters fromempty-chars. If none of the fields of a record are printed then the printing ofrecord_traileris also suppressed. Default isyes. π«empty-chars stringβstringspecifies 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 tofileinstead 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,stringis 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,stringis 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,stringis printed before the records contents. π·οΈelement_header stringβ if record has a level and header name defined,stringis 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 isno. π
π 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βvalueis 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 filename. Every line is considered as a key/value pair separated byseparator. 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 thenameappears in a field list,valuewill be printed for every record as thenamewere 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! π β¨
π¦ where this page comes from
- debian bookworm: ffe 0.3.9-1+b1 Β· GPL-2.0-or-later
- debian trixie: ffe 0.3.9-2 Β· GPL-2.0-or-later
- ubuntu jammy: ffe 0.3.9-1 Β· GPL-2.0-or-later
- ubuntu noble: ffe 0.3.9-1 Β· GPL-2.0-or-later
- ubuntu questing: ffe 0.3.9-4
- ubuntu resolute: ffe 0.3.9-4build1 Β· GPL-2.0-or-later
- ubuntu stonking: ffe 0.3.9-4build1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms