Repository navigation
Expand file tree
/
Copy pathffe.html
More file actions
2053 lines (1917 loc) · 74.2 KB
/
Copy pathffe.html
File metadata and controls
2053 lines (1917 loc) · 74.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents version 0.4.1 of ffe, a flat file extractor.
Copyright (C) 2006-2026 Timo Savinen
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions. -->
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ffe - flat file extractor</title>
<meta name="description" content="ffe - flat file extractor">
<meta name="keywords" content="ffe - flat file extractor">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="#Top" rel="start" title="Top">
<link href="#SEC_Contents" rel="contents" title="Table of Contents">
<link href="dir.html#Top" rel="up" title="(dir)">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
body {
margin: 1%;
padding: 0 5%;
background: white;
font-family: serif;
text-align: justify;
}
h1,h2,h3,h4,h5 {
padding: 0.5em 0 0 0;
font-weight: bold;
font-family: sans-serif;
}
h1 {
padding: 0.5em 0 0.5em 1em;
color: white;
background: #575;
}
pre {
margin: 0;
padding: 0.5em 0.5em 0.5em 0;
}
pre.example {
padding: 0;
margin: 0;
background: #eee;
}
pre.verbatim, .menu {
border: solid 1px gray;
background: white;
padding-bottom: 1em;
}
div.node {
background: #ccc;
margin: 0;
padding: 0 1.5em;
font-weight: lighter;
color: #000;
text-align: right;
}
.node a {
color: #770000;
}
.node a:visited {
color: #550000;
}
dd, li {
padding-top: 0.1em;
padding-bottom: 0.1em;
}
samp {
font: inherit;
}
code {
font-size: inherit;
font-weight: bold;
}
pre, code {
font-family: monospace;
}
.command, .file {
font-family: monospace;
}
div.node hr {
display:none;
}
-->
</style>
</head>
<body lang="en">
<h1 class="settitle" align="center">ffe - flat file extractor</h1>
<span id="Top"></span><span id="ffe"></span><h1 class="top">ffe</h1>
<p>This file documents version 0.4.1 of <code>ffe</code>, a flat file extractor.
</p>
<p>Copyright © 2006-2026 Timo Savinen
</p>
<blockquote>
<p>Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
</p>
<p>Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
</p>
<p>Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
</p></blockquote>
<hr>
<span id="Overview"></span><span id="Preliminary-information"></span><h2 class="chapter">1 Preliminary information</h2>
<span id="index-greetings"></span>
<span id="index-overview"></span>
<p><code>ffe</code> is a program to extract fields from text and binary flat files and to print them in different
formats. The input file structure and printing definitions are specified in a configuration file, which
is always required. Default configuration file is <samp>~/.fferc</samp> (<samp>ffe.rc</samp> in windows).
</p>
<p><code>ffe</code> is a command line tool developed for GNU/Linux and UNIX systems. <code>ffe</code> can read from
standard input and write to standard output, so it can be used as a part of a pipeline.
</p>
<p>There is also a binary distribution for Windows.
</p>
<hr>
<span id="Samples"></span><span id="Samples-using-ffe"></span><h2 class="chapter">2 Samples using <code>ffe</code></h2>
<span id="index-sample"></span>
<p>One example of using <code>ffe</code> for printing personnel information in XML format from a fixed-length flat file:
</p>
<div class="example">
<pre class="example">$ cat personnel
john Ripper 23
Scott Tiger 45
Mary Moore 41
$
</pre></div>
<p>A file <samp>personnel</samp> contains three fixed length fields: ‘<samp>FirstName</samp>’, ‘<samp>LastName</samp>’ and ‘<samp>Age</samp>’,
their respective lengths are 9,13 and 2.
</p>
<p>In order to print data above in XML, following configuration file must be available:
</p>
<div class="example">
<pre class="example">$cat personnel.fferc
structure personel {
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>%t</%n>\n"
record_header "<%r>\n"
record_trailer "</%r>\n"
indent " "
}
$
</pre></div>
<p>Using ffe:
</p>
<div class="example">
<pre class="example">$ffe -c personnel.fferc personnel
<?xml version="1.0" encoding="ISO-8859-1"?>
<person>
<FirstName>john</FirstName>
<LastName>Ripper</LastName>
<Age>23</Age>
</person>
<person>
<FirstName>Scott</FirstName>
<LastName>Tiger</LastName>
<Age>45</Age>
</person>
<person>
<FirstName>Mary</FirstName>
<LastName>Moore</LastName>
<Age>41</Age>
</person>
$
</pre></div>
<hr>
<span id="Invoking-ffe"></span><span id="How-to-run-ffe"></span><h2 class="chapter">3 How to run <code>ffe</code></h2>
<span id="index-running-ffe"></span>
<span id="index-using"></span>
<p><code>ffe</code> is a command line tool. Normally <code>ffe</code> can be invoked as:
</p>
<p><code>ffe -o OUTPUTFILE INPUTFILE…</code>
</p>
<p><code>ffe</code> uses the definitions from the configuration file and tries to guess the input file
structure.
</p>
<p>If the structure cannot be guessed the option <samp>-s</samp> must be used.
</p>
<hr>
<span id="Invocation"></span><span id="Program-invocation"></span><h3 class="section">3.1 Program invocation</h3>
<span id="index-options"></span>
<p>The format for running the <code>ffe</code> program is:
</p>
<div class="example">
<pre class="example">ffe <var>option</var> …
</pre></div>
<p><code>ffe</code> supports the following options:
</p>
<dl compact="compact">
<dt><code>-c <var>file</var></code></dt>
<dt><code>--configuration=<var>file</var></code></dt>
<dd><p>Configuration is read from <var>file</var>, instead of <samp>~/.fferc</samp> (<samp>ffe.rc</samp> in windows).
</p>
</dd>
<dt><code>-s <var>structure</var></code></dt>
<dt><code>--structure=<var>structure</var></code></dt>
<dd><p>Use structure <var>structure</var> for input file, suppresses guessing.
</p>
</dd>
<dt><code>-p <var>output</var></code></dt>
<dt><code>--print=<var>output</var></code></dt>
<dd><p>Use output format <var>output</var> for printing. If not given, then the record or structure related
output format is used. Printing can be suppressed using format <var>no</var>. Original data is printed using format <var>raw</var>.
</p>
</dd>
<dt><code>-o <var>file</var></code></dt>
<dt><code>--output=<var>file</var></code></dt>
<dd><p>Write output to <var>file</var> instead of standard output.
</p>
</dd>
<dt><code>-f <var>list</var></code></dt>
<dt><code>--field-list=<var>list</var></code></dt>
<dd><p>Print only fields and constants listed in the comma separated list <var>list</var>. Order of names in
<var>list</var> specifies also the printing order.
</p>
</dd>
<dt><code>-e <var>expression</var></code></dt>
<dt><code>--expression=<var>expression</var></code></dt>
<dd><p>Print only those records for which the <var>expression</var> evaluates to true.
</p>
</dd>
<dt><code>-a</code></dt>
<dt><code>--and</code></dt>
<dd><p>Expressions are combined with logical and, default is logical or.
Note that if the same field and operator appear several times in expressions they are always compared with logical or (except for comparison operators <code><</code> and <code>></code>, which require a single value per field).
</p>
</dd>
<dt><code>-A <var>name</var></code></dt>
<dt><code>--anonymize=<var>name</var></code></dt>
<dd><p>Anonymize input fields using anonymization set <var>name</var>.
</p>
</dd>
<dt><code>-X</code></dt>
<dt><code>--casecmp</code></dt>
<dd><p>Expressions are evaluated using case insensitive comparison
</p>
</dd>
<dt><code>-v</code></dt>
<dt><code>--invert-match</code></dt>
<dd><p>Print only those records which don’t match the expression.
</p>
</dd>
<dt><code>-l</code></dt>
<dt><code>--loose</code></dt>
<dd><p>Normally <code>ffe</code> stops when it encounters an input line or binary block which doesn’t match any of
the records in selected structure. Defining this option causes <code>ffe</code> to continue despite the error.
Note that invalid lines are reported only for text input. In case of binary input next valid block is silently searched.
</p>
</dd>
<dt><code>-r</code></dt>
<dt><code>--replace=<var>field</var>=<var>value</var></code></dt>
<dd><p>Replace <var>field</var>’s contents with <var>value</var> in output. <var>value</var> can contain same directives as output option <code>data</code>.
</p>
</dd>
<dt><code>-d</code></dt>
<dt><code>--debug</code></dt>
<dd><p>All invalid input lines are written to <samp>ffe_error_<pid>.log</samp>, where <samp><pid></samp> is the process ID.
</p>
</dd>
<dt><code>-I</code></dt>
<dt><code>--info</code></dt>
<dd><p>Show structure information in the configuration file and exit successfully. For every structure the following information is shown:
<br>
Structures: Name, type and maximum record length.
<br>
Records: Name and length
<br>
Fields: Name, position and length. First position is number one.
</p>
</dd>
<dt><code>-?</code></dt>
<dt><code>--help</code></dt>
<dd><p>Print an informative help message describing the options and then exit
successfully.
</p>
</dd>
<dt><code>-V</code></dt>
<dt><code>--version</code></dt>
<dd><p>Print the version number of <code>ffe</code> and then exit successfully.
</p></dd>
</dl>
<p>All remaining options are names of input files, if no input files are specified or <code>-</code> is given, then the standard input is read.
</p>
<span id="Expressions-_0028option-_002de_002c-_002d_002dexpression_0029"></span><h4 class="subheading">Expressions (option <samp>-e</samp>, <samp>--expression</samp>)</h4>
<p>Expression can be used to select specific records comparing field values.
Expression has syntax <var>field</var><strong>x</strong><var>value</var>, where <strong>x</strong> is the comparison operator.
Expression is used to compare field’s contents to <var>value</var> and if comparison is successful
the record is printed. Several expressions can be given and at least one must evaluate to true in
order to print a record. If option <samp>-a</samp> is given all expressions must evaluate to true.
</p>
<p>If <var>value</var> starts with string <code>file:</code> then the rest of <var>value</var> is considered as a file name.
Every line in file is used as <var>value</var> in comparison. Comparison evaluates true if one or more values matches, so this makes it possible to use several different values in comparison. Comparison operators <strong><</strong> and <strong>></strong> do not support <code>file:</code> input. <strong>Note</strong>: The file size is limited by available memory because the file contents is loaded to memory.
</p>
<p>When comparing binary fields the <var>value</var> must have the representation which can be shown using the <code>%d</code> output directive. Note that the printing option <var>hex-caps</var> takes effect in comparison.
</p>
<p>Expression notation:
</p>
<dl compact="compact">
<dt><var>field<strong>=</strong>value</var></dt>
<dd><p>Field <var>field</var> is equal to <var>value</var>.
</p>
</dd>
<dt><var>field<strong>^</strong>value</var></dt>
<dd><p>Field <var>field</var> starts with <var>value</var>.
</p>
</dd>
<dt><var>field<strong>~</strong>value</var></dt>
<dd><p>Field <var>field</var> contains <var>value</var>.
</p>
</dd>
<dt><var>field<strong>#</strong>value</var></dt>
<dd><p>Field <var>field</var> does not contain <var>value</var>.
</p>
</dd>
<dt><var>field<strong>!</strong>value</var></dt>
<dd><p>Field <var>field</var> is not equal to <var>value</var>.
</p>
</dd>
<dt><var>field<strong><</strong>value</var></dt>
<dd><p>Field <var>field</var> is less than <var>value</var>. If both sides are numeric, numerical comparison is used; otherwise, lexicographical comparison (<code>strcmp</code>) is used. Comparison operators <strong><</strong> and <strong>></strong> do not support multiple values for the same field or <code>file:</code> input.
</p>
</dd>
<dt><var>field<strong>></strong>value</var></dt>
<dd><p>Field <var>field</var> is greater than <var>value</var>. If both sides are numeric, numerical comparison is used; otherwise, lexicographical comparison (<code>strcmp</code>) is used. Comparison operators <strong><</strong> and <strong>></strong> do not support multiple values for the same field or <code>file:</code> input.
</p>
</dd>
<dt><var>field<strong>?</strong>value</var></dt>
<dd><p>Field <var>field</var> matches the regular expression <var>value</var>.
<code>ffe</code> supports POSIX extended regular expressions.
</p></dd>
</dl>
<hr>
<span id="Configuration"></span><span id="Configuration-1"></span><h3 class="section">3.2 Configuration</h3>
<span id="index-configuration"></span>
<p><code>ffe</code> uses configuration file in order to read the input file and print the output.
</p>
<p>Configuration file for <code>ffe</code> is a text file. The file may contain empty lines.
Commands are case sensitive. Comments begin with the <code>#</code>-character and end at the end of the line.
The <code>string</code> definitions can be enclosed in double quotation <code>"</code> characters.
<code>char</code> is a single character. <code>string</code> and <code>char</code> can contain following escape codes:
<code>\a</code>, <code>\b</code>, <code>\t</code>, <code>\n</code>, <code>\v</code>, <code>\f</code>, <code>\r</code>, <code>\"</code> and <code>\#</code>.
A backslash can be escaped as <code>\\</code>.
</p>
<p>Configuration has two main parts: the structure, which specifies the input file structure and
the output, which specifies how the input data is formatted for output.
</p>
<span id="Common-syntax"></span><h4 class="subheading">Common syntax</h4>
<p>Common syntax for configuration file is:
</p>
<div class="example">
<pre class="example">#comment
`command`
const <var>name</var> <var>value</var>
filter <var>name</var> <var>value</var>
…
structure <var>name</var> {
<i>option value</i> …
…
record <var>name</var> {
<i>option value</i> …
…
}
record <var>name</var> {
<i>option value</i> …
…
}
…
}
structure <var>name</var> {
…
}
…
output <var>name</var> {
<i>option value</i> …
…
}
output <var>name</var> {
…
}
…
lookup <var>name</var> {
<i>option value</i> …
…
}
lookup <var>name</var> {
…
}
…
</pre></div>
<span id="Structure"></span><h4 class="subheading">Structure</h4>
<p>Keyword <code>structure</code> is used to specify the input file content. An input file can contain several
types of records (lines or binary blocks). E.g. file can have a header, data and trailer record types. Records
must be distinguishable from each other, this can be achieved defining different ’keys’
(<code>id</code> in record definition) or having different line lengths (for fixed length) or different count
of fields (for separated structure) for different records.
</p>
<p>If binary structure has several records, then all records must have at least one key (<code>id</code>), because binary blocks can
be distinguished only by using keys.
</p>
<p>The structure notation:
<br>
</p>
<div class="example">
<pre class="example">structure <var>name</var> {
<i>option value</i> …
…
}
</pre></div>
<p>A structure can contain following options:
</p>
<dl compact="compact">
<dt><code>type fixed|binary|separated [<var>char</var>] [*]</code></dt>
<dd><p>The fields in the input are fixed length fields (text or binary) or text fields separated by <var>char</var>. If * is given,
multiple sequential separators are considered as one. Default separator is comma.
</p>
</dd>
<dt><code>quoted [<var>char</var>]</code></dt>
<dd><p>Fields may be quoted with char, default quotation mark is the double quotation mark ’"’.
A quotation mark is assumed to be escaped as \<var>char</var> or doubling the mark as <var>charchar</var> in input.
Non escaped quotation marks are not preserved in output.
</p>
</dd>
<dt><code>header first|all|no</code></dt>
<dd><p>Controls the occurrence of the header line. Default is no. If set as <em>first</em> or <em>all</em>, the first line
of the first input file is considered as header line containing the names of the fields. <em>first</em>
means that only the first file has a header, <em>all</em> 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 to the record definition, meaning that the name positions, separators etc. are the same as
for the fields. Binary files cannot have a header.
</p>
</dd>
<dt><code>output <var>name</var>|no|raw</code></dt>
<dd><p>All records belonging to this structure are printed according to output format name.
Default is to use output named as ‘<samp>default</samp>’. ‘<samp>no</samp>’ prints nothing and ‘<samp>raw</samp>’ prints only the original data.
</p>
</dd>
<dt><code>record <var>name</var> {<i>options</i> …}</code></dt>
<dd><p>Specifies one record for a structure. A structure can contain several record types.
</p></dd>
</dl>
<span id="Record"></span><h4 class="subheading">Record</h4>
<p>A record specifies one type of input line or binary block in a file. Different records can be distinguished using
the <code>id</code> option or different line lengths or field counts. In multi-record binary structure every record must have at least one <code>id</code> because binary records do not have a special end of record marker as text lines have.
</p>
<p>The record notation:
<br>
</p>
<div class="example">
<pre class="example">record <var>name</var> {
<i>option value</i> …
…
}
</pre></div>
<p>A record can contain following options:
</p>
<dl compact="compact">
<dt><code>id <var>position</var> <var>string</var></code></dt>
<dt><code>rid <var>position</var> <var>regexp</var></code></dt>
<dd><p>Identifies a record in the input file. Records are identified by the <var>string</var> or by the regular expression <var>regexp</var> in input record position
<var>position</var>. For fixed length and binary input the position is the byte position of input record and for
separated input the <var>position</var> is the <var>position</var>’th field of the input record. Positions always start from one.
</p>
<p>A record definition can contain several id’s, then all id’s must match the input line
(<code>id</code>’s are <em>and-ed</em>).
</p>
<p>Non printable characters can be escaped as ‘<samp>\xnn</samp>’, where ‘<samp>nn</samp>’ is the character’s hexadecimal value.
</p>
</dd>
<dt><code>field <var>name</var>|FILLER|* [<var>length</var>]|* [<var>lookup</var>]|* [<var>output</var>]|* [<var>filter</var>]|* [<var>conversion</var>]</code></dt>
<dd><p>Defines a field in a text input structure. <var>length</var> is mandatory for fixed length input structure.
</p>
<p>The last field of a fixed length input structure can have a <em>*</em> in place of <var>length</var>. That means that the last field
has no exact length specified and it gets the remainder of the input line after all other fields. This allows a
fixed record to have an arbitrarily long last field.
</p>
<p>Length is also used for printing the fields in fixed length format (directive <code>%D</code> in output definitions).
</p>
<p>If <em>*</em> is given instead of the name, then the <var>name</var> will be the ordinal number of the field,
or if the <code>header</code> option has value <em>first</em> or <em>all</em>, then the name of the field will be taken from
the header line (first line of the input).
</p>
<p>If <var>lookup</var> is given then the fields contents is used to make a lookup in lookup table <var>lookup</var>.
If <var>length</var> is not needed (separated format) but lookup is needed, use asterisk (*) in place of length definition.
</p>
<p>If <var>output</var> is given the field will be printed using output definition <var>output</var>. If <var>length</var> and/or <var>lookup</var> are not needed use asterisk in place of them. Use asterisk (*) if not needed.
</p>
<p>If <var>filter</var> is given the raw contents of the field is filtered through a program defined by <var>filter</var> and the output of the program is printed as field contents.
</p>
<p>If <var>conversion</var> is given it should contain a single printf style conversion specification, which will be used in printing. Conversion specification must start with <code>%</code> and the last character must be from set <code>diuoxXfeEgGcs</code>.
</p>
<p>If field is named as <code>FILLER</code>, the field will not appear in output.
</p>
<p>The order of fields in configuration file is essential, it specifies the field order in a record.
</p></dd>
<dt><code>field <var>name</var>|FILLER|* <var>length</var>|<var>type</var> [<var>lookup</var>]|* [<var>output</var>]|* [<var>filter</var>]|* [<var>conversion</var>]</code></dt>
<dd><p>Defines a field in a binary structure. All other features are same as for text structure fields except the <var>type</var> parameter.
</p>
<p><var>type</var> specifies the field length and type and can have the following values:
</p>
<dl compact="compact">
<dt><code>char</code></dt>
<dd><p>Printable character.
</p></dd>
<dt><code>short</code></dt>
<dd><p>Short integer having current system length and byte order.
</p></dd>
<dt><code>int</code></dt>
<dd><p>Integer having current system length and byte order.
</p></dd>
<dt><code>long</code></dt>
<dd><p>Long integer having current system length and byte order.
</p></dd>
<dt><code>llong</code></dt>
<dd><p>Long long integer having current system length and byte order.
</p></dd>
<dt><code>ushort</code></dt>
<dd><p>Unsigned short integer having current system length and byte order.
</p></dd>
<dt><code>uint</code></dt>
<dd><p>Unsigned integer having current system length and byte order.
</p></dd>
<dt><code>ulong</code></dt>
<dd><p>Unsigned long integer having current system length and byte order.
</p></dd>
<dt><code>ullong</code></dt>
<dd><p>Unsigned long long integer having current system length and byte order.
</p></dd>
<dt><code>int8</code></dt>
<dd><p>8 bit integer.
</p></dd>
<dt><code>int16_be</code></dt>
<dd><p>Big endian 16 bit integer.
</p></dd>
<dt><code>int32_be</code></dt>
<dd><p>Big endian 32 bit integer.
</p></dd>
<dt><code>int64_be</code></dt>
<dd><p>Big endian 64 bit integer.
</p></dd>
<dt><code>int16_le</code></dt>
<dd><p>Little endian 16 bit integer.
</p></dd>
<dt><code>int32_le</code></dt>
<dd><p>Little endian 32 bit integer.
</p></dd>
<dt><code>int64_le</code></dt>
<dd><p>Little endian 64 bit integer.
</p></dd>
<dt><code>uint8</code></dt>
<dd><p>Unsigned 8 bit integer.
</p></dd>
<dt><code>uint16_be</code></dt>
<dd><p>Unsigned big endian 16 bit integer.
</p></dd>
<dt><code>uint32_be</code></dt>
<dd><p>Unsigned big endian 32 bit integer.
</p></dd>
<dt><code>uint64_be</code></dt>
<dd><p>Unsigned big endian 64 bit integer.
</p></dd>
<dt><code>uint16_le</code></dt>
<dd><p>Unsigned little endian 16 bit integer.
</p></dd>
<dt><code>uint32_le</code></dt>
<dd><p>Unsigned little endian 32 bit integer.
</p></dd>
<dt><code>uint64_le</code></dt>
<dd><p>Unsigned little endian 64 bit integer.
</p></dd>
<dt><code>float</code></dt>
<dd><p>Float having current system length and byte order.
</p></dd>
<dt><code>float_be</code></dt>
<dd><p>Float having current system length and big endian byte order.
</p></dd>
<dt><code>float_le</code></dt>
<dd><p>Float having current system length and little endian byte order.
</p></dd>
<dt><code>double</code></dt>
<dd><p>Double having current system length and byte order.
</p></dd>
<dt><code>double_be</code></dt>
<dd><p>Double having current system length and big endian byte order.
</p></dd>
<dt><code>double_le</code></dt>
<dd><p>Double having current system length and little endian byte order.
</p></dd>
<dt><code>bcd_be_<var>len</var></code></dt>
<dd><p>Bcd number having length <var>len</var> and nybbles in big endian order.
</p></dd>
<dt><code>bcd_le_<var>len</var></code></dt>
<dd><p>Bcd number having length <var>len</var> and nybbles in little endian order.
</p></dd>
<dt><code>hex_be_<var>len</var></code></dt>
<dd><p>Hexadecimal data in big endian order having length <var>len</var>.
</p></dd>
<dt><code>hex_le_<var>len</var></code></dt>
<dd><p>Hexadecimal data in little endian order having length <var>len</var>.
</p></dd>
</dl>
<p>If <var>length</var> is given instead of the <var>type</var>, then the field is assumed to be a printable string having length <var>length</var>. String is printed until <var>length</var> characters are printed or NULL character is found.
</p>
<p>Bcd number (<code>bcd_be_<var>len</var></code> and <code>bcd_le_<var>len</var></code>) is printed until <var>len</var> bytes are read or a nybble having hexadecimal value <code>f</code> is found.
Bcd number having big endian order is printed in order: most significant nybble first and least significant nybble second and bcd number having little endian order is printed in order: least significant nybble first and most significant nybble second. Bytes are always read in big endian order.
</p>
<p>Hexadecimal data (<code>hex_be_<var>len</var></code> and <code>hex_le_<var>len</var></code>) is printed as hexadecimal values. Big endian data is printed starting from lower address and little endian data starting from upper address.
</p>
</dd>
<dt><code>field-count <var>number</var></code></dt>
<dd><p>Same effect as having "<code>field *</code>" <var>number</var> times. This can be used in separated structure instead of
writing sequential "<code>field *</code>" definitions. Several <code>field-count</code>s can be used in the same record and
they can be mixed with <code>field</code>.
</p></dd>
<dt><code>fields-from <var>record</var></code></dt>
<dd><p>Fields in this record are the same as in record <var>record</var>. <code>field</code> and <code>fields-from</code> are mutually
exclusive.
</p></dd>
<dt><code>output <var>name</var>|no|raw</code></dt>
<dd><p>This record is printed according to output format <var>name</var>. Default is to use output format specified in structure.
</p></dd>
<dt><code>level <var>number</var> [<var>element_name</var>|*] [<var>group_name</var>]</code></dt>
<dd><p>Levels can be used to print the file in hierarchical multi-level nested form document.
<var>number</var> is the level of the record, starting from number one (highest level),
<var>element_name</var> is the name for the record, <var>group_name</var>
is used to group records in the same and lower levels. Only <var>number</var> is mandatory.
Use * instead of the element name if group name is needed.
</p></dd>
<dt><code>record-length strict|minimum</code></dt>
<dd><dl compact="compact">
<dt><code>strict</code></dt>
<dd><p>Input record length (fixed format) or field count (separated format) must match the record definition in order to get it processed. This is the default value.
</p></dd>
<dt><code>minimum</code></dt>
<dd><p>Input record length or field count can be the same or longer as defined for the record. The rest of the input line is ignored.
</p></dd>
</dl>
</dd>
<dt><code>variable-length <var>record_length</var> <var>variable_length_field</var> <var>adjust</var></code></dt>
<dd><p><var>record_length</var> and <var>variable_length_field</var> are the names of two fields in the record and <var>adjust</var> is a signed integer.
Record length is read from field <var>record_length</var>. <var>record_length</var> is assumed to be an integer type for binary structures or contain only decimal numbers in fixed length structure.
<var>record_length</var> is assumed to contain the total length of the record.
<var>variable_length_field</var> is the field having variable length. The length of <var>variable_length_field</var> is calculated by subtracting the total length of all other fields from the length read from <var>record_length</var>.
<br>
The length given by keyword <var>field</var> for <var>variable_length_field</var> is ignored. After calculating the length it is adjusted by <var>adjust</var>. <var>adjust</var> can be used in cases where the length read from <var>variable_length_field</var> does not contain the total length of the record. variable-length can be used with binary or fixed-length structures only.
</p></dd>
</dl>
<span id="Output"></span><h4 class="subheading">Output</h4>
<p>Keyword <code>output</code> specifies an output format for formatting the input data for output. Formatting
is controlled using options and printf style directives. An output definition is independent
from structure, so one output format can be used with different input file formats.
</p>
<p>The output notation:
<br>
</p>
<div class="example">
<pre class="example">output <var>name</var> {
<i>option value</i> …
…
}
</pre></div>
<p>Actual formatting and printing is controlled using <em>pictures</em> in output options. Pictures can contain
following printf style directives:
</p>
<dl compact="compact">
<dt><code>%f</code></dt>
<dd><p>Name of the input file.
</p></dd>
<dt><code>%s</code></dt>
<dd><p>Name of the current structure.
</p></dd>
<dt><code>%r</code></dt>
<dd><p>Name of the current record.
</p></dd>
<dt><code>%o</code></dt>
<dd><p>Input record number in current file.
</p></dd>
<dt><code>%O</code></dt>
<dd><p>Input record number starting from the first file.
</p></dd>
<dt><code>%i</code></dt>
<dd><p>Byte offset of the current record in the current file. Starts from zero.
</p></dd>
<dt><code>%I</code></dt>
<dd><p>Byte offset of the current record starting from the first file. Starts from zero.
</p></dd>
<dt><code>%n</code></dt>
<dd><p>Field name.
</p></dd>
<dt><code>%t</code></dt>
<dd><p>Field contents, without leading and trailing white-spaces.
</p></dd>
<dt><code>%d</code></dt>
<dd><p>Field contents. Binary integer is printed as a decimal value. Floating point number is printed in the style <code>[-]ddd.ddd</code>, 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.
</p></dd>
<dt><code>%D</code></dt>
<dd><p>Field contents, right padded to the field length (requires length definition for the field).
</p></dd>
<dt><code>%C</code></dt>
<dd><p>Field contents, right padded to the field length (requires length definition for the field). Contents is cut if the input field
is longer than output length.
</p></dd>
<dt><code>%x</code></dt>
<dd><p>Unsigned hexadecimal value of a binary integer. Other fields are printed as directive <code>%d</code> would be used.
</p></dd>
<dt><code>%l</code></dt>
<dd><p>Lookup value which has been found using current field as a search key.
</p></dd>
<dt><code>%L</code></dt>
<dd><p>Lookup value, right padded to the field length.
</p></dd>
<dt><code>%p</code></dt>
<dd><p>Fields start position in a record. For fixed and binary 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.
</p></dd>
<dt><code>%h</code></dt>
<dd><p>Hexadecimal dump of a field. Byte values are printed as consecutive <code>xnn</code> values, where the <code>nn</code> is the hexadecimal value of a byte. Data is printed before any endian conversion.
</p></dd>
<dt><code>%e</code></dt>
<dd><p>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></dd>
<dt><code>%g</code></dt>
<dd><p>Group name given by the keyword <code>group_name</code> in record definition.
</p></dd>
<dt><code>%m</code></dt>
<dd><p>Element name given by the keyword <code>element_name</code> in record definition.
</p></dd>
<dt><code>%%</code></dt>
<dd><p>Percent sign.
</p></dd>
</dl>
<p>Output options:
</p><dl compact="compact">
<dt><code>file_header <var>picture</var></code></dt>
<dd><p><var>picture</var> is printed once before file contents.
</p></dd>
<dt><code>file_trailer <var>picture</var></code></dt>
<dd><p><var>picture</var> is printed once after file contents.
</p></dd>
<dt><code>header <var>picture</var></code></dt>
<dd><p>If given, then the header line describing the field names is printed before records.
Every field name is printed according to the <var>picture</var> using the same separator and field length as
given for the fields. Picture can contain only <code>%n</code> directive.
</p></dd>
<dt><code>data <var>picture</var></code></dt>
<dd><p>Field contents is printed according to <var>picture</var>.
</p></dd>
<dt><code>lookup <var>picture</var></code></dt>
<dd><p>If current field is related to lookup table, then this <var>picture</var> is used instead of picture from <code>data</code>.
This makes it possible to use a different picture when the field is related to a lookup table. Default is to use the picture from <code>data</code>.
</p></dd>
<dt><code>separator <var>string</var></code></dt>
<dd><p>All fields are terminated by <var>string</var>, except the last field of the record.
Default is not to print separator.
</p></dd>
<dt><code>record_header <var>picture</var></code></dt>
<dd><p><var>picture</var> is printed before the record content. Default is not to print the record header.
</p></dd>
<dt><code>record_trailer <var>picture</var></code></dt>
<dd><p><var>picture</var> is printed after the record content. Default is newline.
</p></dd>
<dt><code>justify left|right|<var>char</var></code></dt>
<dd><p>The output from the <code>data</code> option is left or right justified.
<var>char</var> justifies output according to the first occurrence of <var>char</var>
in the data picture. Default is left.
</p></dd>
<dt><code>indent <var>string</var></code></dt>
<dd><p>Record contents is indented by <var>string</var>.
Field contents is indented by two times the string. Default is not to indent.
If file contents is printed in hierarchical form (keyword <code>level</code> in record definition) then
contents is indented according to the level of a record.
</p></dd>
<dt><code>field-list <var>name1</var>,<var>name2</var>,…</code></dt>
<dd><p>Only fields and constants named as <var>name1</var>,<var>name2</var>,… are printed, same effect as has option <samp>-f</samp>.
Default is print all fields and no constants. Fields and constants are also printed in the same order as they are listed.
</p></dd>
<dt><code>no-data-print yes|no</code></dt>
<dd><p>If <code>field-list</code> is given and this is set to no, and none of the fields in <code>field-list</code>
belong to the current record, then the <code>record_header</code> and <code>record_trailer</code> are not printed.
Default is yes.
</p></dd>
<dt><code>field-empty-print yes|no</code></dt>
<dd><p>When set as no, nothing is printed for the fields which consist entirely of characters from <code>empty-chars</code>.
If none of the fields of a record are printed, then the printing of <code>record_trailer</code> is also suppressed.
Default is yes.
</p></dd>
<dt><code>empty-chars <var>string</var></code></dt>
<dd><p><var>string</var> specifies a set of characters which define an "empty" field. Default is
" \f\n\r\t\v"<!-- /@w --> (space, form-feed, newline, carriage return, horizontal tab and vertical tab).
</p></dd>
<dt><code>output-file <var>file</var></code></dt>
<dd><p>Output is written to <var>file</var> instead of the default output (standard output or given by <samp>-o, --output</samp>).
If - is given the output is written to standard output.
</p></dd>
<dt><code>group_header <var>picture</var></code></dt>
<dd><p>If a record has a level and a group name defined,
<var>picture</var> is printed before the first record in a group or if the group name has changed in the same level.
<strong>Note</strong>: Level related pictures can contain printing directives <code>%g</code> and <code>%n</code> only.
</p></dd>
<dt><code>group_trailer <var>picture</var></code></dt>
<dd><p>If a record has a level and a group name defined,
<var>picture</var> is printed after the records in lower levels are printed or if the group name has changed in the
same level or if a higher level record is found.
</p></dd>
<dt><code>element_header <var>picture</var></code></dt>
<dd><p>If a record has a level and an element name defined, <var>picture</var> is printed before the record’s contents.
</p></dd>
<dt><code>element_trailer <var>picture</var></code></dt>
<dd><p>If a record has a level and an element name defined, <var>picture</var> is printed after the record’s contents or after
the following lower level records.
</p></dd>
<dt><code>hex-caps yes|no</code></dt>
<dd><p>Print hexadecimal numbers in capital letters. Default is no.
</p></dd>
</dl>
<span id="Lookup"></span><h4 class="subheading">Lookup</h4>
<p>Keyword <code>lookup</code> specifies a lookup table which can be searched using field contents. Found values can
be printed using output directives <code>%l</code> and <code>%L</code>.
</p>
<p>The lookup table notation:
<br>
</p>
<div class="example">
<pre class="example">lookup <var>name</var> {
<i>option value</i> …
…
}
</pre></div>
<p>Lookup options:
</p><dl compact="compact">
<dt><code>search exact | longest</code></dt>
<dd><p>Search method for this table. Either exact or longest match is used when searching the table. Default is <code>exact</code>.
</p></dd>
<dt><code>pair <var>key</var> <var>value</var></code></dt>
<dd><p>Defines a key/value pair for the lookup table. In case of binary file <var>key</var> must have the same representation as
can be shown using the <code>%d</code> printing directive.
</p></dd>
<dt><code>file <var>name</var> [<var>separator</var>]</code></dt>
<dd><p>Data for the lookup table is read from file <var>name</var>. Each line in file <var>name</var> is considered as a key/value pair
separated by a single character <var>separator</var>. Default separator is semicolon. Lines without separator are silently omitted.
<strong>Note</strong>: The file size is limited by available memory because the file contents is loaded to memory.
</p></dd>
<dt><code>default-value <var>value</var></code></dt>
<dd><p>If searching the lookup table is unsuccessful then <var>value</var> is used in printing. Default is empty string.
</p></dd>
</dl>
<span id="Constants"></span><h4 class="subheading">Constants</h4>
<p>Keyword <code>const</code> specifies one name/value pair which can be used as an additional output field.
Constants can be used only in field lists (option <samp>-f,--field-list</samp>, or output option <code>field-list</code>).
</p>
<p>Constants can be used to add fields to output which do not appear in input. E.g. new fields for
separated output or adding spaces after a fixed length field (changing the field length).
</p>
<p>Note that <var>value</var> is printed as it is for every record. It cannot be changed record by record.
</p>
<p>If a constant has the same name as one of the input fields, the value <var>value</var> is printed instead of
the input field contents.
</p>
<p>The constant notation:
<br>
</p>
<div class="example">
<pre class="example">const <var>name</var> <var>value</var>
</pre></div>
<p>When <var>name</var> appears in field list it is treated as one of the input fields having contents <var>value</var>.
</p>
<span id="Filter"></span><h4 class="subheading">Filter</h4>
<p>Keyword <code>filter</code> defines a command that can be used to format field raw contents. Command must read the standard input
and write to standard output and it must not block. Field raw contents is filtered through the command and the output is printed as
field contents.
</p>
<p>The filter notation:
<br>
</p><div class="example">
<pre class="example">filter <var>name</var> <var>command</var>
</pre></div>
<p><var>name</var> is referenced in the field definition. <var>command</var> is the shell command to be executed.
</p>
<span id="Anonymization"></span><h4 class="subheading">Anonymization</h4>
<p>Keyword <code>anonymize</code> defines a set of fields that will be anonymized when the command line option <samp>-A,--anonymize</samp>
is given. <code>ffe</code> uses non-reversible anonymization methods and preserves the original field length.
</p>
<p>Notation:
<br>
</p><div class="example">
<pre class="example">anonymize <var>name</var> {
<i>method</i> …
…
}
</pre></div>
<p>The anonymization will be done if command line option <samp>-A,--anonymize</samp> is given with <var>name</var>.
Anonymize options:
</p><dl compact="compact">
<dt><code>method <var>field</var> <var>method</var> [<var>start</var>] [<var>length</var>] [<var>parameter</var>]</code></dt>
<dd><p>All fields named <var>field</var> in the current structure will be anonymized using method <var>method</var>.
As default the whole field is anonymized. Some parts of the field can be left non-anonymized using
<var>start</var> and <var>length</var>. <var>start</var> is the byte position where the anonymization starts, first byte is number 1.
If <var>start</var> is negative the anonymization starts backwards from the end of the field (e.g. -1 refers to the last byte).
If <var>length</var> is given then <var>length</var> number of bytes is anonymized after start position, default value 0 means the rest of the field.
Only <var>field</var> and <var>method</var> are mandatory.
<br>
<br>
Values for <var>method</var>:
</p><dl compact="compact">
<dt><code>MASK</code></dt>
<dd><p>Field will be masked with character ’0’. A different masking character can be given with <var>parameter</var>.